Class: MinimalPipeline::Sqs

Inherits:
Object
  • Object
show all
Defined in:
lib/minimal_pipeline/sqs.rb

Overview

Here is an example of how to use this class to send a message onto a queue.

“` sqs = MinimalPipeline::Sqs.new message = 'Beep boop' sqs.send_message('queue-name', message) “`

Instance Method Summary collapse

Constructor Details

#initializeSqs

Returns a new instance of Sqs.


12
13
14
15
16
17
18
# File 'lib/minimal_pipeline/sqs.rb', line 12

def initialize
  raise 'You must set env variable AWS_REGION or region.' \
    if ENV['AWS_REGION'].nil? && ENV['region'].nil?

  region = ENV['AWS_REGION'] || ENV['region']
  @client = Aws::SQS::Client.new(region: region)
end

Instance Method Details

#send_message(queue_name, body) ⇒ Aws::SQS::Types::SendMessageResult

Places a message on a SQS queue

Parameters:

  • queue_name (String)

    The name of the SQS queue

  • body (String)

    The message body to place on the queue

Returns:

  • (Aws::SQS::Types::SendMessageResult)

    The result object


25
26
27
28
29
# File 'lib/minimal_pipeline/sqs.rb', line 25

def send_message(queue_name, body)
  queue_url = @client.get_queue_url(queue_name: queue_name).queue_url
  @client.send_message(queue_url: queue_url, message_body: body,
                       message_group_id: queue_name)
end