Class: Banter::Server::ClientQueueListener
- Inherits:
-
Object
- Object
- Banter::Server::ClientQueueListener
- Includes:
- Celluloid
- Defined in:
- lib/banter/server/client_queue_listener.rb
Instance Attribute Summary collapse
-
#worker_class ⇒ Object
readonly
Returns the value of attribute worker_class.
Instance Method Summary collapse
-
#initialize(worker_class, request_key, queue_name, durable = true, pool_size = 100, topic = nil) ⇒ ClientQueueListener
constructor
A new instance of ClientQueueListener.
- #message_received(delivery_info, properties, envelope) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(worker_class, request_key, queue_name, durable = true, pool_size = 100, topic = nil) ⇒ ClientQueueListener
Returns a new instance of ClientQueueListener.
13 14 15 16 17 18 19 |
# File 'lib/banter/server/client_queue_listener.rb', line 13 def initialize(worker_class, request_key, queue_name, durable = true, pool_size = 100, topic = nil) @topic = topic || Banter::Configuration.topic_prefix @request_key = request_key @worker_class = worker_class @queue_name = queue_name @subscriber = ::Banter::Server::RabbitMQSubscriber.new(@request_key, @queue_name, worker_class.queue_ttl, durable, pool_size, @topic) end |
Instance Attribute Details
#worker_class ⇒ Object (readonly)
Returns the value of attribute worker_class.
11 12 13 |
# File 'lib/banter/server/client_queue_listener.rb', line 11 def worker_class @worker_class end |
Instance Method Details
#message_received(delivery_info, properties, envelope) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/banter/server/client_queue_listener.rb', line 32 def (delivery_info, properties, envelope) Banter::RabbitLogger.log(::Logger::DEBUG, "Message received by listener on #{worker_class.name} with payload: #{envelope[:payload]}") worker = worker_class.new(delivery_info, properties, envelope[:context]) payload = envelope[:payload] (worker, payload) worker.perform!(payload) rescue ::Banter::PayloadValidationError => banter_error (banter_error, false) Banter::RabbitLogger.log(::Logger::ERROR, { worker: worker_class.name, message: banter_error., envelope: envelope }) Airbrake.notify(banter_error, params: { info: delivery_info, properties: properties, context: envelope[:context], payload: envelope[:payload], message: "Validation error for #{worker_class.name}" }) rescue => e (e, true) Banter::RabbitLogger.log(::Logger::DEBUG, "Failed message for #{worker_class.name} #{e.}") Airbrake.notify(e, params: { info: delivery_info, properties: properties, context: envelope[:context], payload: envelope[:payload], message: "Failed perform for #{worker_class.name}" }) end |
#shutdown ⇒ Object
28 29 30 |
# File 'lib/banter/server/client_queue_listener.rb', line 28 def shutdown @subscriber.teardown if @subscriber.present? end |
#start ⇒ Object
21 22 23 24 25 26 |
# File 'lib/banter/server/client_queue_listener.rb', line 21 def start @subscriber.start(false) do |delivery_info, properties, envelope| (delivery_info, properties, envelope) true end end |