Class: Huck::Receivers::RabbitMQReceiver
- Inherits:
-
Huck::Receiver
- Object
- Huck::Receiver
- Huck::Receivers::RabbitMQReceiver
- Defined in:
- lib/huck/receivers/rabbitmq.rb
Overview
A receiver that talks to RabbitMQ
Instance Attribute Summary
Attributes inherited from Huck::Receiver
Instance Method Summary collapse
-
#initialize ⇒ RabbitMQReceiver
constructor
Includes all required modules for the RabbitMQ receiver.
-
#receive ⇒ Object
A long-running poller process which reads messages out of the remote queue and yields them to higher-order logic.
-
#verify_config ⇒ Object
Ensures that configuration is set properly before trying to use the connection data to talk to RabbitMQ.
Methods inherited from Huck::Receiver
Constructor Details
#initialize ⇒ RabbitMQReceiver
Includes all required modules for the RabbitMQ receiver
9 10 11 |
# File 'lib/huck/receivers/rabbitmq.rb', line 9 def initialize Huck::must_load 'bunny' end |
Instance Method Details
#receive ⇒ Object
A long-running poller process which reads messages out of the remote queue and yields them to higher-order logic.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/huck/receivers/rabbitmq.rb', line 26 def receive verify_config = Hash.new [:host, :port, :user, :pass, :vhost].each do |arg| if @config['rabbitmq'].has_key? arg.to_s [arg] = @config['rabbitmq'][arg.to_s] end end conn = Bunny.new conn.start ch = conn.create_channel queue = ch.queue(@config['rabbitmq']['queue_name']) queue.subscribe :block => true do |_, _, msg| yield msg end end |
#verify_config ⇒ Object
Ensures that configuration is set properly before trying to use the connection data to talk to RabbitMQ
15 16 17 18 19 20 21 22 |
# File 'lib/huck/receivers/rabbitmq.rb', line 15 def verify_config if !@config.has_key? 'rabbitmq' raise Huck::Error, 'missing rabbitmq config' end if !@config['rabbitmq'].has_key? 'queue_name' raise Huck::Error, 'missing rabbitmq receiver config: queue_name' end end |