mirror of
https://github.com/jimeh/bunnyrun.git
synced 2026-02-19 07:56:40 +00:00
Add some basic examples
This commit is contained in:
1
examples/application-example/.gitignore
vendored
Normal file
1
examples/application-example/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Gemfile.lock
|
||||
3
examples/application-example/Gemfile
Normal file
3
examples/application-example/Gemfile
Normal file
@@ -0,0 +1,3 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'bunnyrun', path: '../..'
|
||||
11
examples/application-example/bin/foobar
Executable file
11
examples/application-example/bin/foobar
Executable file
@@ -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)
|
||||
5
examples/application-example/lib/foobar.rb
Normal file
5
examples/application-example/lib/foobar.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'foobar/consumers'
|
||||
require 'foobar/version'
|
||||
|
||||
module Foobar
|
||||
end
|
||||
2
examples/application-example/lib/foobar/consumers.rb
Normal file
2
examples/application-example/lib/foobar/consumers.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
require 'foobar/ping_consumer'
|
||||
require 'foobar/pong_consumer'
|
||||
20
examples/application-example/lib/foobar/ping_consumer.rb
Normal file
20
examples/application-example/lib/foobar/ping_consumer.rb
Normal file
@@ -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
|
||||
20
examples/application-example/lib/foobar/pong_consumer.rb
Normal file
20
examples/application-example/lib/foobar/pong_consumer.rb
Normal file
@@ -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
|
||||
3
examples/application-example/lib/foobar/version.rb
Normal file
3
examples/application-example/lib/foobar/version.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
module Foobar
|
||||
VERSION = '0.1.0'.freeze
|
||||
end
|
||||
3
examples/application-example/run_example.sh
Executable file
3
examples/application-example/run_example.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
bundle check || bundle install
|
||||
|
||||
exec bundle exec bin/foobar
|
||||
18
examples/basic-consumers-example/ping_consumer.rb
Normal file
18
examples/basic-consumers-example/ping_consumer.rb
Normal file
@@ -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
|
||||
18
examples/basic-consumers-example/pong_consumer.rb
Normal file
18
examples/basic-consumers-example/pong_consumer.rb
Normal file
@@ -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
|
||||
1
examples/basic-consumers-example/run_example.sh
Executable file
1
examples/basic-consumers-example/run_example.sh
Executable file
@@ -0,0 +1 @@
|
||||
exec ../../exe/bunnyrun ping_consumer.rb pong_consumer.rb
|
||||
Reference in New Issue
Block a user