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.
Add example and more detailed description for GenRMQ.Processor (#146)
- Loading branch information
Joel C
authored
Mar 9, 2020
1 parent
a6fe01f
commit 317c475
Showing
3 changed files
with
32 additions
and
4 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
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,24 @@ | ||
defmodule ExampleProcessor do | ||
@moduledoc """ | ||
Example GenRMQ.Processor implementation | ||
Sample usage: | ||
``` | ||
iex -S mix | ||
iex(1)> ExampleProcessor.process(%GenRMQ.Message{payload: "Hello", attributes: [], state: %{}}) | ||
Received message: %GenRMQ.Message{attributes: [], payload: "Hello", state: %{}} | ||
iex(2)> ExampleProcessor.process(%GenRMQ.Message{payload: "error", attributes: [], state: %{}}) | ||
** (RuntimeError) Exception triggered by message | ||
(gen_rmq) examples/processor.ex:18: ExampleProcessor.process/1 | ||
``` | ||
""" | ||
|
||
@behaviour GenRMQ.Processor | ||
|
||
def process(%GenRMQ.Message{payload: "error"}), do: raise("Exception triggered by message") | ||
|
||
def process(%GenRMQ.Message{} = message) do | ||
IO.puts("Received message: #{inspect(message)}") | ||
:ok | ||
end | ||
end |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
defmodule GenRMQ.Processor do | ||
@moduledoc """ | ||
Defines functions to implement by any AMQP processor | ||
Behaviour module for implementing a RabbitMQ message processor. | ||
A message processor is typically used to separate out business logic from a consumer, | ||
to let the consumer only deal with RabbitMQ specifics. | ||
""" | ||
|
||
@callback process(message :: %GenRMQ.Message{}) :: :ok | {:error, term} | ||
end |