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
1 changed file
with
28 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Publisher with default exchange | ||
=============================== | ||
|
||
> [The default exchange](https://www.rabbitmq.com/tutorials/amqp-concepts.html#exchange-default) is a direct exchange with no name (empty string) pre-declared by the broker. It has one special property that makes it very useful for simple applications: every queue that is created is automatically bound to it with a routing key which is the same as the queue name. | ||
# Example | ||
|
||
~~~elixir | ||
defmodule WithDefaultExchange do | ||
@behaviour GenRMQ.Publisher | ||
|
||
def start_link() do | ||
GenRMQ.Publisher.start_link(__MODULE__, name: __MODULE__) | ||
end | ||
|
||
def publish_message(message, routing_key) do | ||
Logger.info("Publishing message #{inspect(message)}") | ||
GenRMQ.Publisher.publish(__MODULE__, message, routing_key) | ||
end | ||
|
||
def init() do | ||
[ | ||
exchange: :default, | ||
connection: "amqp://guest:guest@localhost:5672" | ||
] | ||
end | ||
end | ||
~~~ |