From f9546dcc614d5d0c4ef302b731a0ee607c957ea9 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Tue, 21 Mar 2017 22:12:06 +0000 Subject: [PATCH] Add some basic examples --- examples/application-example/.gitignore | 1 + examples/application-example/Gemfile | 3 +++ examples/application-example/bin/foobar | 11 ++++++++++ examples/application-example/lib/foobar.rb | 5 +++++ .../lib/foobar/consumers.rb | 2 ++ .../lib/foobar/ping_consumer.rb | 20 +++++++++++++++++++ .../lib/foobar/pong_consumer.rb | 20 +++++++++++++++++++ .../application-example/lib/foobar/version.rb | 3 +++ examples/application-example/run_example.sh | 3 +++ .../basic-consumers-example/ping_consumer.rb | 18 +++++++++++++++++ .../basic-consumers-example/pong_consumer.rb | 18 +++++++++++++++++ .../basic-consumers-example/run_example.sh | 1 + 12 files changed, 105 insertions(+) create mode 100644 examples/application-example/.gitignore create mode 100644 examples/application-example/Gemfile create mode 100755 examples/application-example/bin/foobar create mode 100644 examples/application-example/lib/foobar.rb create mode 100644 examples/application-example/lib/foobar/consumers.rb create mode 100644 examples/application-example/lib/foobar/ping_consumer.rb create mode 100644 examples/application-example/lib/foobar/pong_consumer.rb create mode 100644 examples/application-example/lib/foobar/version.rb create mode 100755 examples/application-example/run_example.sh create mode 100644 examples/basic-consumers-example/ping_consumer.rb create mode 100644 examples/basic-consumers-example/pong_consumer.rb create mode 100755 examples/basic-consumers-example/run_example.sh diff --git a/examples/application-example/.gitignore b/examples/application-example/.gitignore new file mode 100644 index 0000000..b844b14 --- /dev/null +++ b/examples/application-example/.gitignore @@ -0,0 +1 @@ +Gemfile.lock diff --git a/examples/application-example/Gemfile b/examples/application-example/Gemfile new file mode 100644 index 0000000..112d7fd --- /dev/null +++ b/examples/application-example/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'bunnyrun', path: '../..' diff --git a/examples/application-example/bin/foobar b/examples/application-example/bin/foobar new file mode 100755 index 0000000..a7fcb0e --- /dev/null +++ b/examples/application-example/bin/foobar @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +$LOAD_PATH.unshift(File.expand_path('../../lib', File.realpath(__FILE__))) +require 'bunnyrun' +require 'foobar' + +cli = BunnyRun::CLI.new( + name: File.basename(__FILE__), + version: Foobar::VERSION +) + +cli.run(ARGV) diff --git a/examples/application-example/lib/foobar.rb b/examples/application-example/lib/foobar.rb new file mode 100644 index 0000000..6046187 --- /dev/null +++ b/examples/application-example/lib/foobar.rb @@ -0,0 +1,5 @@ +require 'foobar/consumers' +require 'foobar/version' + +module Foobar +end diff --git a/examples/application-example/lib/foobar/consumers.rb b/examples/application-example/lib/foobar/consumers.rb new file mode 100644 index 0000000..5dc562d --- /dev/null +++ b/examples/application-example/lib/foobar/consumers.rb @@ -0,0 +1,2 @@ +require 'foobar/ping_consumer' +require 'foobar/pong_consumer' diff --git a/examples/application-example/lib/foobar/ping_consumer.rb b/examples/application-example/lib/foobar/ping_consumer.rb new file mode 100644 index 0000000..4273402 --- /dev/null +++ b/examples/application-example/lib/foobar/ping_consumer.rb @@ -0,0 +1,20 @@ +require 'bunnyrun' + +module Foobar + class PingConsumer < BunnyRun::Consumer + queue 'ping' + + exchange 'ping-pong', type: :direct + bind 'ping-pong', routing_key: 'ping' + + manual_ack true # default is false + + def perform(message) + logger.info "#{self.class} received: #{message.payload}" + sleep 1 + + publish('ping-pong', 'PONG', routing_key: 'pong') + message.ack + end + end +end diff --git a/examples/application-example/lib/foobar/pong_consumer.rb b/examples/application-example/lib/foobar/pong_consumer.rb new file mode 100644 index 0000000..84d802a --- /dev/null +++ b/examples/application-example/lib/foobar/pong_consumer.rb @@ -0,0 +1,20 @@ +require 'bunnyrun' + +module Foobar + class PongConsumer < BunnyRun::Consumer + queue 'pong' + + exchange 'ping-pong', type: :direct + bind 'ping-pong', routing_key: 'pong' + + manual_ack true # default is false + + def perform(message) + logger.info "#{self.class} received: #{message.payload}" + sleep 1 + + publish('ping-pong', 'PING', routing_key: 'ping') + message.ack + end + end +end diff --git a/examples/application-example/lib/foobar/version.rb b/examples/application-example/lib/foobar/version.rb new file mode 100644 index 0000000..4d43786 --- /dev/null +++ b/examples/application-example/lib/foobar/version.rb @@ -0,0 +1,3 @@ +module Foobar + VERSION = '0.1.0'.freeze +end diff --git a/examples/application-example/run_example.sh b/examples/application-example/run_example.sh new file mode 100755 index 0000000..360802b --- /dev/null +++ b/examples/application-example/run_example.sh @@ -0,0 +1,3 @@ +bundle check || bundle install + +exec bundle exec bin/foobar diff --git a/examples/basic-consumers-example/ping_consumer.rb b/examples/basic-consumers-example/ping_consumer.rb new file mode 100644 index 0000000..0308312 --- /dev/null +++ b/examples/basic-consumers-example/ping_consumer.rb @@ -0,0 +1,18 @@ +require 'bunnyrun' + +class PingConsumer < BunnyRun::Consumer + queue 'ping' + + exchange 'ping-pong', type: :direct + bind 'ping-pong', routing_key: 'ping' + + manual_ack true # default is false + + def perform(message) + logger.info "#{self.class} received: #{message.payload}" + sleep 1 + + publish('ping-pong', 'PONG', routing_key: 'pong') + message.ack + end +end diff --git a/examples/basic-consumers-example/pong_consumer.rb b/examples/basic-consumers-example/pong_consumer.rb new file mode 100644 index 0000000..d90084a --- /dev/null +++ b/examples/basic-consumers-example/pong_consumer.rb @@ -0,0 +1,18 @@ +require 'bunnyrun' + +class PongConsumer < BunnyRun::Consumer + queue 'pong' + + exchange 'ping-pong', type: :direct + bind 'ping-pong', routing_key: 'pong' + + manual_ack true # default is false + + def perform(message) + logger.info "#{self.class} received: #{message.payload}" + sleep 1 + + publish('ping-pong', 'PING', routing_key: 'ping') + message.ack + end +end diff --git a/examples/basic-consumers-example/run_example.sh b/examples/basic-consumers-example/run_example.sh new file mode 100755 index 0000000..d210285 --- /dev/null +++ b/examples/basic-consumers-example/run_example.sh @@ -0,0 +1 @@ +exec ../../exe/bunnyrun ping_consumer.rb pong_consumer.rb