LoginSignup
6
3

More than 5 years have passed since last update.

Amazon SQSを使ってみた

Last updated at Posted at 2017-08-02

分かったこと

Rubyから使う場合

キューに追加

sqs = Aws::SQS::Client.new
sqs.send_message(
  queue_url: "https://sqs.ap-northeast-1.amazonaws.com/123445/queue_name",
  message_body: {
    id: 1,
    title: 'title',
    created_at: Time.current
  }.to_json
)

キューから取得

poller = Aws::SQS::QueuePoller.new("https://sqs.ap-northeast-1.amazonaws.com/123445/queue_name")
poller.poll(max_number_of_messages: 10, idle_timeout: 60) do |msg|
  result = JSON.parse(msg.body)
end

Elixirから使う場合

追加したパッケージ

{:ex_aws, "~> 1.0"},
{:poison, "~> 2.0"},
{:hackney, "~> 1.6"},
{:sweet_xml, "~> 0.6.5"}

キューに追加

body = %{"id" => 1, "title" => "title", "created_at" => DateTime.utc_now() } |> Poison.encode!
ExAws.SQS.send_message("/123445/queue_name", body) |> ExAws.request!(region: "ap-northeast-1")
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3