This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
359 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Consumer basic setup | ||
==================== | ||
|
||
# Example | ||
|
||
~~~elixir | ||
defmodule ConsumerBasicSetup do | ||
@behaviour GenRMQ.Consumer | ||
|
||
def init() do | ||
[ | ||
connection: "amqp://guest:guest@localhost:5672", | ||
queue: "example_queue", | ||
exchange: "example_exchange", | ||
routing_key: "routing_key.#", | ||
prefetch_count: "10" | ||
] | ||
end | ||
|
||
def handle_message(%GenRMQ.Message{} = message), do: GenRMQ.Consumer.ack(message) | ||
|
||
def consumer_tag(), do: "consumer-tag" | ||
|
||
def start_link(), do: GenRMQ.Consumer.start_link(__MODULE__, name: __MODULE__) | ||
end | ||
|
||
~~~ | ||
|
||
# Outcome: | ||
|
||
- durable `example_exchange.deadletter` exchange created or redeclared | ||
- durable `example_queue_error` queue created or redeclared and bound to `example_exchange.deadletter` exchange | ||
- durable topic `example_exchange` exchange created or redeclared | ||
- durable `example_queue` queue created or redeclared and bound to `example_exchange` exchange | ||
- queue `example_queue` has a deadletter exchange set to `example_exchange.deadletter` | ||
- every `handle_message` callback will be executed in a separate process | ||
- on failed rabbitmq connection it will wait for a bit and then reconnect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Consumer Telemetry events | ||
|
||
GenRMQ emits [Telemetry][telemetry] events for consumers. It currently exposes the following events: | ||
|
||
- `[:gen_rmq, :consumer, :message, :ack]` - Dispatched by a GenRMQ consumer when a message has been acknowledged | ||
|
||
- Measurement: `%{time: System.monotonic_time}` | ||
- Metadata: `%{message: String.t}` | ||
|
||
- `[:gen_rmq, :consumer, :message, :reject]` - Dispatched by a GenRMQ consumer when a message has been rejected | ||
|
||
- Measurement: `%{time: System.monotonic_time}` | ||
- Metadata: `%{message: String.t, requeue: boolean}` | ||
|
||
- `[:gen_rmq, :consumer, :message, :start]` - Dispatched by a GenRMQ consumer when the processing of a message has begun | ||
|
||
- Measurement: `%{time: System.monotonic_time}` | ||
- Metadata: `%{message: String.t, module: atom}` | ||
|
||
- `[:gen_rmq, :consumer, :message, :stop]` - Dispatched by a GenRMQ consumer when the processing of a message has completed | ||
|
||
- Measurement: `%{time: System.monotonic_time, duration: native_time}` | ||
- Metadata: `%{message: String.t, module: atom}` | ||
|
||
- `[:gen_rmq, :consumer, :connection, :start]` - Dispatched by a GenRMQ consumer when a connection to RabbitMQ is started | ||
|
||
- Measurement: `%{time: System.monotonic_time}` | ||
- Metadata: `%{module: atom, attempt: integer, queue: String.t, exchange: String.t, routing_key: String.t}` | ||
|
||
- `[:gen_rmq, :consumer, :connection, :stop]` - Dispatched by a GenRMQ consumer when a connection to RabbitMQ has been established | ||
|
||
- Measurement: `%{time: System.monotonic_time, duration: native_time}` | ||
- Metadata: `%{module: atom, attempt: integer, queue: String.t, exchange: String.t, routing_key: String.t}` | ||
|
||
- `[:gen_rmq, :consumer, :connection, :error]` - Dispatched by a GenRMQ consumer when a connection to RabbitMQ could not be made | ||
|
||
- Measurement: `%{time: System.monotonic_time}` | ||
- Metadata: `%{module: atom, attempt: integer, queue: String.t, exchange: String.t, routing_key: String.t, error: any}` | ||
|
||
- `[:gen_rmq, :consumer, :connection, :down]` - Dispatched by a GenRMQ consumer when a connection to RabbitMQ has been lost | ||
|
||
- Measurement: `%{time: System.monotonic_time}` | ||
- Metadata: `%{module: atom, reason: atom}` |
56 changes: 56 additions & 0 deletions
56
documentation/guides/consumer/with_custom_deadletter_configuration.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
Consumer with custom deadletter configuration | ||
============================================= | ||
|
||
Consumer with custom deadletter: | ||
|
||
- queue name | ||
- exchange name | ||
- routing key | ||
- queue arguments and type (transient instead of durable) | ||
|
||
`deadletter_queue_options` - Queue options for the deadletter queue as declared in | ||
[AMQP.Queue.declare/3](https://hexdocs.pm/amqp/AMQP.Queue.html#declare/3). | ||
|
||
# Example | ||
|
||
~~~elixir | ||
defmodule ConsumerWithCustomDeadletterConfiguration do | ||
@behaviour GenRMQ.Consumer | ||
|
||
def init() do | ||
[ | ||
connection: "amqp://guest:guest@localhost:5672", | ||
queue: "example_queue", | ||
exchange: "example_exchange", | ||
routing_key: "routing_key.#", | ||
prefetch_count: "10", | ||
deadletter_queue: "custom_deadletter_queue", | ||
deadletter_exchange: "custom_deadletter_exchange", | ||
deadletter_routing_key: "custom_deadletter_routing_key", | ||
deadletter_queue_options: [ | ||
durable: false, | ||
arguments: [ | ||
{"x-expires", :long, 3_600_000}, | ||
{"x-max-priority", :long, 3} | ||
] | ||
] | ||
] | ||
end | ||
|
||
def handle_message(%GenRMQ.Message{} = message), do: GenRMQ.Consumer.ack(message) | ||
|
||
def consumer_tag(), do: "consumer-tag" | ||
|
||
def start_link(), do: GenRMQ.Consumer.start_link(__MODULE__, name: __MODULE__) | ||
end | ||
~~~ | ||
|
||
# Outcome: | ||
|
||
- durable `custom_deadletter_exchange` exchange created or redeclared | ||
- transient, priority and with ttl `custom_deadletter_queue` queue created or redeclared and bound to `custom_deadletter_exchange` exchange | ||
- durable topic `example_exchange` exchange created or redeclared | ||
- durable `example_queue` queue created or redeclared and bound to `example_exchange` exchange | ||
- queue `example_queue` has a deadletter exchange set to `custom_deadletter_exchange` | ||
- every `handle_message` callback will be executed in a separate process | ||
- on failed rabbitmq connection it will wait for a bit and then reconnect |
39 changes: 39 additions & 0 deletions
39
documentation/guides/consumer/with_custom_exchange_type.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Consumer with custom exchange | ||
============================= | ||
|
||
By default consumer creates `topic` exchanges. This can be modified by | ||
specyfying exchange type: `exchange: {:fanout, "custom_exchange"}`. | ||
|
||
# Example | ||
|
||
~~~elixir | ||
defmodule WithCustomExchangeType do | ||
@behaviour GenRMQ.Consumer | ||
|
||
def init() do | ||
[ | ||
connection: "amqp://guest:guest@localhost:5672", | ||
queue: "example_queue", | ||
exchange: {:fanout, "custom_exchange"}, | ||
routing_key: "routing_key.#", | ||
prefetch_count: "10" | ||
] | ||
end | ||
|
||
def handle_message(%GenRMQ.Message{} = message), do: GenRMQ.Consumer.ack(message) | ||
|
||
def consumer_tag(), do: "consumer-tag" | ||
|
||
def start_link(), do: GenRMQ.Consumer.start_link(__MODULE__, name: __MODULE__) | ||
end | ||
~~~ | ||
|
||
# Outcome: | ||
|
||
- durable `example_exchange.deadletter` exchange created or redeclared | ||
- durable `example_queue_error` queue created or redeclared and bound to `example_exchange.deadletter` exchange | ||
- durable fanout `custom_exchange` exchange created or redeclared | ||
- durable `example_queue` queue created or redeclared and bound to `custom_exchange` exchange | ||
- queue `example_queue` has a deadletter exchange set to `example_exchange.deadletter` | ||
- every `handle_message` callback will be executed in a separate process | ||
- on failed rabbitmq connection it will wait for a bit and then reconnect |
46 changes: 46 additions & 0 deletions
46
documentation/guides/consumer/with_custom_queue_configuration.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Consumer with custom queue options | ||
================================== | ||
|
||
`queue_options` - Queue options as declared in | ||
[AMQP.Queue.declare/3](https://hexdocs.pm/amqp/AMQP.Queue.html#declare/3). | ||
|
||
# Example | ||
|
||
~~~elixir | ||
defmodule ConsumerWithCustomQueueConfiguration do | ||
@behaviour GenRMQ.Consumer | ||
|
||
def init() do | ||
[ | ||
connection: "amqp://guest:guest@localhost:5672", | ||
queue: "example_queue", | ||
exchange: "example_exchange", | ||
routing_key: "routing_key.#", | ||
prefetch_count: "10", | ||
queue_options: [ | ||
durable: false, | ||
arguments: [ | ||
{"x-expires", :long, 3_600_000}, | ||
{"x-max-priority", :long, 3} | ||
] | ||
] | ||
] | ||
end | ||
|
||
def handle_message(%GenRMQ.Message{} = message), do: GenRMQ.Consumer.ack(message) | ||
|
||
def consumer_tag(), do: "consumer-tag" | ||
|
||
def start_link(), do: GenRMQ.Consumer.start_link(__MODULE__, name: __MODULE__) | ||
end | ||
~~~ | ||
|
||
# Outcome: | ||
|
||
- durable `example_exchange.deadletter` exchange created or redeclared | ||
- durable `example_queue_error` queue created or redeclared and bound to `example_exchange.deadletter` exchange | ||
- durable topic `example_exchange` exchange created or redeclared | ||
- transient, priority and with ttl `example_queue` queue created or redeclared and bound to `example_exchange` exchange | ||
- queue `example_queue` has a deadletter exchange set to `example_exchange.deadletter` | ||
- every `handle_message` callback will be executed in a separate process | ||
- on failed rabbitmq connection it will wait for a bit and then reconnect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
Consumer with quorum queues | ||
=========================== | ||
|
||
You can change from `classic` to a `quorum` queue type by specyfing corresponding | ||
queue arguments. Read more about quorum queues [here](https://www.rabbitmq.com/quorum-queues.html). | ||
|
||
# Example | ||
|
||
~~~elixir | ||
defmodule WithQuorumQueueType do | ||
@behaviour GenRMQ.Consumer | ||
|
||
def init() do | ||
[ | ||
connection: "amqp://guest:guest@localhost:5672", | ||
queue: "example_queue", | ||
exchange: "example_exchange", | ||
routing_key: "routing_key.#", | ||
prefetch_count: "10", | ||
queue_options: [ | ||
arguments: [ | ||
{"x-queue-type", :longstr, "quorum"} | ||
] | ||
], | ||
deadletter_queue_options: [ | ||
arguments: [ | ||
{"x-queue-type", :longstr, "quorum"} | ||
] | ||
] | ||
] | ||
end | ||
|
||
def handle_message(%GenRMQ.Message{} = message), do: GenRMQ.Consumer.ack(message) | ||
|
||
def consumer_tag(), do: "consumer-tag" | ||
|
||
def start_link(), do: GenRMQ.Consumer.start_link(__MODULE__, name: __MODULE__) | ||
end | ||
~~~ | ||
|
||
# Outcome: | ||
|
||
- durable `example_exchange.deadletter` exchange created or redeclared | ||
- durable `example_queue_error` **quorum** queue created or redeclared and bound to `example_exchange.deadletter` exchange | ||
- durable topic `example_exchange` exchange created or redeclared | ||
- durable `example_queue` **quorum** queue created or redeclared and bound to `example_exchange` exchange | ||
- queue `example_queue` has a deadletter exchange set to `example_exchange.deadletter` | ||
- every `handle_message` callback will be executed in a separate process | ||
- on failed rabbitmq connection it will wait for a bit and then reconnect |
Oops, something went wrong.