Add some basic examples

This commit is contained in:
2017-03-21 22:12:06 +00:00
parent b2faab4d5f
commit f9546dcc61
12 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
require 'foobar/consumers'
require 'foobar/version'
module Foobar
end

View File

@@ -0,0 +1,2 @@
require 'foobar/ping_consumer'
require 'foobar/pong_consumer'

View 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

View 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

View File

@@ -0,0 +1,3 @@
module Foobar
VERSION = '0.1.0'.freeze
end