-
-
Notifications
You must be signed in to change notification settings - Fork 288
Sending a message
Pablo Cantero edited this page Oct 8, 2016
·
12 revisions
There are a couple ways to send a message using Shoryuken.
Using perform_async
:
MyWorker.perform_async('Pablo')
it also accepts a Hash as a parameter, which is automatically converted into JSON:
MyWorker.perform_async(field: 'test', other_field: 'other')
it's also possible to override where the job is queued to with an options hash:
MyWorker.perform_async('Pablo') # will queue to the default queue
MyWorker.perform_async('Pablo', queue: 'important') # will queue to the 'important' queue
Or using the queue object directly , which wraps Aws::SQS::Client:
# To send a single message
Shoryuken::Client.queues('default').send_message('msg 1')
# To send a single message as a Hash you need to put it in a hash with `message_body` as the key.
Shoryuken::Client.queues('default').send_message(message_body: { example: "data" })
# To send multiple messages
Shoryuken::Client.queues('default').send_messages(['msg 1', 'msg 2'])
You can delay a message up to 15 minutes.
MyWorker.perform_in(60, 'Pablo') # 60 seconds
MyWorker.perform_at(Time.now, 'Pablo')
Check AWS credentials to make sure you have your aws-sdk before sending messages.