Class: Huck::Receivers::SQSReceiver
- Inherits:
-
Huck::Receiver
- Object
- Huck::Receiver
- Huck::Receivers::SQSReceiver
- Defined in:
- lib/huck/receivers/sqs.rb
Overview
A receiver that talks to Amazon Simple Queue Service
Instance Attribute Summary
Attributes inherited from Huck::Receiver
Instance Method Summary collapse
-
#initialize ⇒ SQSReceiver
constructor
Includes all required modules for the SQS 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 AWS.
Methods inherited from Huck::Receiver
Constructor Details
#initialize ⇒ SQSReceiver
Includes all required modules for the SQS receiver
9 10 11 |
# File 'lib/huck/receivers/sqs.rb', line 9 def initialize Huck::must_load 'aws-sdk' 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.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/huck/receivers/sqs.rb', line 29 def receive verify_config sqs = AWS::SQS.new( :access_key_id => @config['sqs']['access_key_id'], :secret_access_key => @config['sqs']['secret_access_key'], :region => @config['sqs']['region'] ) queue = sqs.queues.create @config['sqs']['queue_name'] queue.poll do |msg| yield msg.body end end |
#verify_config ⇒ Object
Ensures that configuration is set properly before trying to use the connection data to talk to AWS
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/huck/receivers/sqs.rb', line 15 def verify_config if !@config.has_key? 'sqs' raise Huck::Error, 'missing sqs config' end ['access_key_id', 'secret_access_key', 'region', 'queue_name'].each do |key| if !@config['sqs'].has_key? key raise Huck::Error, "missing sqs config: #{key}" end end end |