Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add connection behaviour and architecture docs #21

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,14 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/coinga
## License

The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

## Architecture
```mermaid
graph TD;
A[ApplicationSupervisor] --> B[ConsumerSupervisor];
A --> C[ConnectionServer - GenServer];
C -- sends requests to start consumers --> B;
B -- dynamic supervisor of multiple -->D[ConsumerServer - GenServer];
D -- monitors --> E[ConsumerExecutor];
E -- sends messages to --> C;
```
23 changes: 23 additions & 0 deletions lib/coney/connection.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule Coney.Connection do
alias AMQP

@callback open(settings :: map()) :: {:ok, Connection.t()} | {:error, any()}

@callback create_channel(Connection.t()) :: Channel.t()

@callback subscribe(Channel.t(), pid(), consumer :: any()) ::
{:ok, String.t()} | {:error, :blocked} | {:error, :closing}

@callback publish(
conn :: Connection.t(),
exchange :: String.t(),
routing_key :: String.t(),
message :: any()
) :: :ok | {:error, any()}

@callback confirm(Channel.t(), tag :: any()) :: :ok | {:error, any()}

@callback reject(Channel.t(), tag :: any(), opts :: Keyword.t()) :: :ok | {:error, any()}

@callback init_topology(Connection.t(), topology :: map()) :: :ok | {:error, Basic.error()}
end
2 changes: 2 additions & 0 deletions lib/coney/fake_connection.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule Coney.FakeConnection do
@behaviour Coney.Connection

def open(_) do
:conn
end
Expand Down
2 changes: 2 additions & 0 deletions lib/coney/rabbit_connection.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Coney.RabbitConnection do
use AMQP

@behaviour Coney.Connection

require Logger

def open(%{url: url, timeout: timeout} = settings) do
Expand Down