Reputation: 28245
The Amazon SDK for Ruby changes frequently, the current version of the aws-sdk
Ruby gem is 2.0.29. The old method of polling Amazon SQS messages is no longer valid
# polling SQS Queue
queue.poll do |msg|
puts "Got message: #{msg.body}"
end
What is the correct method now for the version 2.0 of the AWS SDK for Ruby?
Upvotes: 0
Views: 2244
Reputation: 6357
You may check Shoryuken, it's built on top of SQS and also integration with Rails (ActiveJob). But you can also use it without Rails, in a standalone Ruby app.
Upvotes: 0
Reputation: 6528
The version 2 SDK does not implement queue polling yet. It is on the SDK backlog as a feature request: https://github.com/aws/aws-sdk-ruby/blob/master/FEATURE_REQUESTS.md#amazon-sqs-queue-poller.
Upvotes: 1
Reputation: 6947
In the documentation of the latest Ruby AWS SDK, I do not see a polling method. However, there is a method receive_message
. The details are at http://docs.aws.amazon.com/sdkforruby/api/Aws/SQS/Client.html#receive_message-instance_method
Also, you can configure your SQS to always return a message in response. Here are the details http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html
You will need to make sure the connection does not timeout in case you have to wait too long for the message to arrive and be delivered to you.
Lastly, you can mimic the poll method by calling the receive_message
in a while loop and only breaking out of the loop once the response contains some messages. You can employ recursion to process all the messages in a similar fashion.
Updated March 12, 2015
You will also need to delete the message if you want to imitate the poll method.
Upvotes: 1