conduitframework / conduit_sqs

MIT License
11 stars 8 forks source link
aws conduit elixir message-queue sqs

ConduitSQS

CircleCI Coveralls Hex.pm Hex.pm Hex.pm Gratipay

A Conduit adapter for SQS.

Installation

The package can be installed by adding conduit_sqs to your list of dependencies in mix.exs:

def deps do
  [{:conduit_sqs, "~> 0.3.0"}]
end

Configuring the Adapter

config :my_app, MyApp.Broker,
  adapter: ConduitSQS,
  access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
  secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]

Options

Configuring Queues

Inside the configure block of a broker, you can define queues that will be created at application startup with the options you specify.

defmodule MyApp.Broker do
  configure do
    queue "my-queue"
    queue "my-other-queue.fifo", fifo_queue: true
  end
end

Options

For creating a queue, ConduitSQS supports the same options that are specified in the SQS docs. See the SQS docs for creating a queue to understand what each of the options mean. These options include:

In addition to the SQS options, you can also pass the following:

Configuring a Subscriber

Inside an incoming block for a broker, you can define subscriptions to queues. Conduit will route messages on those queues to your subscribers.

defmodule MyApp.Broker do
  incoming MyApp do
    subscribe :my_subscriber, MySubscriber, from: "my-queue"
    subscribe :my_other_subscriber, MyOtherSubscriber,
      from: "my-other-queue",
      max_number_of_messages: 10,
      worker_pool_size: 1
  end
end

Options

ConduitSQS requires that you specify a from option, which states which queue to consume from.

For subscribing to a queue, ConduitSQS supports the same options that are specified in the SQS docs. See the SQS docs for receiving a message to understand what each of the options mean. These options include:

For attribute_names and message_attributes, ConduitSQS will attempt to pull all attributes unless overriden. ConduitSQS defaults max_number_of_messages to 10, which is the largest that SQS supports.

In addition to the SQS options, you can also pass the following:

Configuring a Publisher

Inside an outgoing block for a broker, you can define publications to queues. Conduit will deliver messages using the options specified. You can override these options, by passing different options to your broker's publish/3.

defmodule MyApp.Broker do
  outgoing do
    publish :something, to: "my-queue"
    publish :something_else,
      to: "my-other-queue",
      delay_seconds: 11
  end
end

Options

For publishing to a queue, ConduitSQS supports the same options that are specified in the SQS docs. See the SQS docs for publishing a message to understand what each of the options mean. These options include:

These options may also be specified by setting headers on the message being published. Headers on the message will trump any options specified in an outgoing block. For example:

message =
  %Conduit.Message{}
  |> put_header("message_group_id", "22")

ConduitSQS does not allow you to set the message_attributes option. Those will be filled from properties on the message and from the message headers.

In addition to the SQS options, you can also pass the following: