-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start ConnectionServer before ConsumerSupervisor * Keep channels in ConnectionServer state, pass a reference to the consumers * Close channels before closing connection when terminating ConnectionServer * Add logs, Mermaid diagram, tests and documentation
- Loading branch information
1 parent
c8ccc00
commit 953760e
Showing
17 changed files
with
347 additions
and
88 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
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,5 +1,8 @@ | ||
services: | ||
rabbitmq: | ||
image: "rabbitmq:alpine" | ||
# "management" version is not required, but it makes | ||
# manual testing easier | ||
image: "rabbitmq:3.12-management-alpine" | ||
ports: | ||
- "5672:5672" | ||
- "15672:15672" |
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 |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import Config | ||
|
||
config :coney, | ||
topology: %{ | ||
exchanges: [{:topic, "exchange", durable: false}], | ||
queues: %{ | ||
"queue" => %{ | ||
options: [ | ||
durable: false | ||
], | ||
bindings: [ | ||
[exchange: "exchange", options: [routing_key: "queue"]] | ||
] | ||
} | ||
} | ||
}, | ||
adapter: Coney.RabbitConnection, | ||
pool_size: 1, | ||
auto_start: true, | ||
settings: %{ | ||
url: "amqp://guest:guest@localhost:5672", | ||
timeout: 1000 | ||
}, | ||
workers: [] | ||
workers: [ | ||
FakeConsumer | ||
] |
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
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
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,16 +1,19 @@ | ||
defmodule Coney.ConsumerSupervisor do | ||
use DynamicSupervisor | ||
@moduledoc """ | ||
Supervisor for all ConsumerServer of the application. | ||
""" | ||
use Supervisor | ||
|
||
def start_link(_args) do | ||
DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__) | ||
end | ||
alias Coney.ConsumerServer | ||
|
||
def init([]) do | ||
DynamicSupervisor.init(strategy: :one_for_one) | ||
def start_link([consumers]) do | ||
Supervisor.start_link(__MODULE__, [consumers], name: __MODULE__) | ||
end | ||
|
||
def start_consumer(consumer, chan) do | ||
spec = {Coney.ConsumerServer, [consumer, chan]} | ||
DynamicSupervisor.start_child(__MODULE__, spec) | ||
@impl Supervisor | ||
def init([consumers]) do | ||
children = Enum.map(consumers, fn consumer -> {ConsumerServer, [consumer]} end) | ||
|
||
Supervisor.init(children, strategy: :one_for_one) | ||
end | ||
end |
Oops, something went wrong.