Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Rename project to gen_rmq (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorszun authored Mar 14, 2018
1 parent d78ccf2 commit b344596
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 145 deletions.
29 changes: 0 additions & 29 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,30 +1 @@
# Changelog

## [0.1.6] - 2018-03-02
### Added
- Required project configuration to publish on [hex.pm](hex.pm) @mkorszun.

## [0.1.5] - 2018-02-28
### Added
- Possibility to control concurrency in consumer @mkorszun.
- Possibility to make `app_id` configurable for publisher @mkorszun.
- Better `ExDoc` documentation

### Fixed
- If `queue_ttl` specified it also applies to dead letter queue @mkorszun.
- Default `routing_key` on publish

## [0.1.4] - 2018-02-06
### Added
- Possibility to specify queue ttl in consumer config @mkorszun.

## [0.1.3] - 2018-01-31
### Added
- Processor behaviour @mkorszun.
### Removed
- Unused test helper functions @mkorszun.

[0.1.6]: https://github.com/meltwater/gen_amqp/compare/v0.1.5...v0.1.6
[0.1.5]: https://github.com/meltwater/gen_amqp/compare/v0.1.4...v0.1.5
[0.1.4]: https://github.com/meltwater/gen_amqp/compare/v0.1.3...v0.1.4
[0.1.3]: https://github.com/meltwater/gen_amqp/compare/v0.1.2...v0.1.3
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Build Status](https://travis-ci.com/meltwater/gen_amqp.svg?token=JscQvnQYQz7Pr7TwvyZh&branch=master)](https://travis-ci.com/meltwater/gen_amqp)
[![Build Status](https://travis-ci.org/meltwater/gen_rmq.svg?branch=master)](https://travis-ci.org/meltwater/gen_rmq)

# GenAMQP
# GenRMQ

GenAMQP is a set of [behaviours](https://hexdocs.pm/elixir/behaviours.html) meant to be used to create RabbitMQ consumers and publishers.
GenRMQ is a set of [behaviours](https://hexdocs.pm/elixir/behaviours.html) meant to be used to create RabbitMQ consumers and publishers.
Internally it is using [AMQP](https://github.com/pma/amqp) elixir RabbitMQ client. The idea is to reduce boilerplate consumer / publisher
code, which usually includes:

Expand All @@ -12,25 +12,25 @@ code, which usually includes:

The project currently provides the following functionality:

- `GenAMQP.Consumer` - a behaviour for implementing RabbitMQ consumers
- `GenAMQP.Publisher` - a behaviour for implementing RabbitMQ publishers
- `GenAMQP.Processor` - a behaviour for implementing RabbitMQ message processors
- `GenAMQP.RabbitCase` - test utilities for RabbitMQ ([example usage](test/gen_amqp_publisher_test.exs))
- `GenRMQ.Consumer` - a behaviour for implementing RabbitMQ consumers
- `GenRMQ.Publisher` - a behaviour for implementing RabbitMQ publishers
- `GenRMQ.Processor` - a behaviour for implementing RabbitMQ message processors
- `GenRMQ.RabbitCase` - test utilities for RabbitMQ ([example usage](test/gen_rmq_publisher_test.exs))

## Examples

More thorough examples for using `GenAMQP.Consumer` and `GenAMQP.Publisher` can be found in the [examples](examples) directory.
More thorough examples for using `GenRMQ.Consumer` and `GenRMQ.Publisher` can be found in the [examples](examples) directory.

### Consumer

~~~elixir
defmodule Consumer do
@behaviour GenAMQP.Consumer
@behaviour GenRMQ.Consumer

def init() do
[
queue: "gen_amqp_in_queue",
exchange: "gen_amqp_exchange",
queue: "gen_rmq_in_queue",
exchange: "gen_rmq_exchange",
routing_key: "#",
prefetch_count: "10",
uri: "amqp://guest:guest@localhost:5672",
Expand All @@ -49,48 +49,48 @@ end
~~~

~~~elixir
GenAMQP.Consumer.start_link(Consumer, name: Consumer)
GenRMQ.Consumer.start_link(Consumer, name: Consumer)
~~~

This will result in:
* durable `gen_amqp_exchange.deadletter` exchange created or redeclared
* durable `gen_amqp_in_queue_error` queue created or redeclared. It will be bound to `gen_amqp_exchange.deadletter`
* durable `gen_amqp_exchange` exchange created or redeclared
* durable `gen_amqp_in_queue` queue created or redeclared. It will be bound to `gen_amqp_exchange`
exchange and has a deadletter exchange set to `gen_amqp_exchange.deadletter`
* on failed rabbitmq connection it will wait for a bit and then reconnect
* durable `gen_rmq_exchange.deadletter` exchange created or redeclared
* durable `gen_rmq_in_queue_error` queue created or redeclared. It will be bound to `gen_rmq_exchange.deadletter`
* durable `gen_rmq_exchange` exchange created or redeclared
* durable `gen_rmq_in_queue` queue created or redeclared. It will be bound to `gen_rmq_exchange`
exchange and has a deadletter exchange set to `gen_rmq_exchange.deadletter`
* every `handle_message` callback will executed in separate process. This can be disabled by setting `concurrency: false` in `init` callback
* on failed rabbitmq connection it will wait for a bit and then reconnect

For all available options please check [consumer documentation](lib/consumer.ex).

### Publisher

~~~elixir
defmodule Publisher do
@behaviour GenAMQP.Publisher
@behaviour GenRMQ.Publisher

def init() do
[
exchange: "gen_amqp_exchange",
exchange: "gen_rmq_exchange",
uri: "amqp://guest:guest@localhost:5672"
]
end
end
~~~

~~~elixir
GenAMQP.Publisher.start_link(Publisher, name: Publisher)
GenAMQP.Publisher.publish(Publisher, Poison.encode!(%{msg: "msg"}))
GenRMQ.Publisher.start_link(Publisher, name: Publisher)
GenRMQ.Publisher.publish(Publisher, Poison.encode!(%{msg: "msg"}))
~~~

## Installation
~~~elixir
def deps do
[
{
:gen_amqp,
git: "git@github.com:meltwater/gen_amqp.git",
tag: "v0.1.6"
:gen_rmq,
git: "git@github.com:meltwater/gen_rmq.git",
tag: "v0.1.7"
}
]
end
Expand All @@ -104,7 +104,7 @@ $ make test

## How to contribute
We happily accept contributions in the form of [Github PRs](https://help.github.com/articles/about-pull-requests/)
or in the form of bug reports, comments/suggestions or usage questions by creating a [github issue](https://github.com/meltwater/gen_amqp/issues).
or in the form of bug reports, comments/suggestions or usage questions by creating a [github issue](https://github.com/meltwater/gen_rmq/issues).

## Notes on project maturity
This library was developed as a Meltwater internal project starting in January 2018.
Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use Mix.Config

# You can configure your application as:
#
# config :gen_amqp, key: :value
# config :gen_rmq, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:gen_amqp, :key)
# Application.get_env(:gen_rmq, :key)
#
# You can also configure a 3rd-party app:
#
Expand Down
14 changes: 7 additions & 7 deletions examples/consumer.ex
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
defmodule MyApp.ExampleConsumer do
@moduledoc """
Example GenAMQP.Consumer implementation
Example GenRMQ.Consumer implementation
"""
@behaviour GenAMQP.Consumer
@behaviour GenRMQ.Consumer

require Logger

alias Mix.Project
alias GenAMQP.Message
alias GenRMQ.Message

##############################################################################
# Consumer API
##############################################################################

def start_link() do
GenAMQP.Consumer.start_link(__MODULE__, name: __MODULE__)
GenRMQ.Consumer.start_link(__MODULE__, name: __MODULE__)
end

def ack(%Message{attributes: %{delivery_tag: tag}} = message) do
Logger.debug("Message successfully processed. Tag: #{tag}")
GenAMQP.Consumer.ack(message)
GenRMQ.Consumer.ack(message)
end

def reject(%Message{attributes: %{delivery_tag: tag}} = message, requeue \\ true) do
Logger.info("Rejecting message, tag: #{tag}, requeue: #{requeue}")
GenAMQP.Consumer.reject(message, requeue)
GenRMQ.Consumer.reject(message, requeue)
end

##############################################################################
# GenAMQP.Consumer callbacks
# GenRMQ.Consumer callbacks
##############################################################################

def init() do
Expand Down
8 changes: 4 additions & 4 deletions examples/publisher.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
defmodule MyApp.ExamplePublisher do
@moduledoc """
Example GenAMQP.Publisher implementation
Example GenRMQ.Publisher implementation
"""

@behaviour GenAMQP.Publisher
@behaviour GenRMQ.Publisher

require Logger

def start_link() do
GenAMQP.Publisher.start_link(__MODULE__, name: __MODULE__)
GenRMQ.Publisher.start_link(__MODULE__, name: __MODULE__)
end

def publish_message(message) do
Logger.info("Publishing message #{inspect(message)}")
GenAMQP.Publisher.publish(__MODULE__, message)
GenRMQ.Publisher.publish(__MODULE__, message)
end

def init() do
Expand Down
34 changes: 17 additions & 17 deletions lib/consumer.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule GenAMQP.Consumer do
defmodule GenRMQ.Consumer do
@moduledoc """
A behaviour module for implementing the RabbitMQ consumer.
Expand All @@ -14,10 +14,10 @@ defmodule GenAMQP.Consumer do
use AMQP

require Logger
alias GenAMQP.Message
alias GenRMQ.Message

##############################################################################
# GenConsumer callbacks
# GenRMQ.Consumer callbacks
##############################################################################

@doc """
Expand Down Expand Up @@ -59,8 +59,8 @@ defmodule GenAMQP.Consumer do
```
def init() do
[
queue: "gen_amqp_in_queue",
exchange: "gen_amqp_exchange",
queue: "gen_rmq_in_queue",
exchange: "gen_rmq_exchange",
routing_key: "#",
prefetch_count: "10",
uri: "amqp://guest:guest@localhost:5672",
Expand Down Expand Up @@ -99,28 +99,28 @@ defmodule GenAMQP.Consumer do
@doc """
Invoked on message delivery
`message` - `GenAMQP.Message` struct
`message` - `GenRMQ.Message` struct
## Examples:
```
def handle_message(message) do
# Do something with message and acknowledge it
GenAMQP.Consumer.ack(message)
GenRMQ.Consumer.ack(message)
end
```
"""
@callback handle_message(message :: GenAMQP.Message.t()) :: :ok
@callback handle_message(message :: GenRMQ.Message.t()) :: :ok

##############################################################################
# GenConsumer API
# GenRMQ.Consumer API
##############################################################################

@doc """
Starts `GenAMQP.Consumer` process with given callback module linked to the current
Starts `GenRMQ.Consumer` process with given callback module linked to the current
process
`module` - callback module implementing `GenAMQP.Consumer` behaviour
`module` - callback module implementing `GenRMQ.Consumer` behaviour
## Options
* `:name` - used for name registration
Expand All @@ -133,7 +133,7 @@ defmodule GenAMQP.Consumer do
## Examples:
```
GenAMQP.Consumer.start_link(Consumer, name: :consumer)
GenRMQ.Consumer.start_link(Consumer, name: :consumer)
```
"""
Expand All @@ -150,7 +150,7 @@ defmodule GenAMQP.Consumer do
## Examples:
```
GenAMQP.Consumer.stop(:consumer, :normal)
GenRMQ.Consumer.stop(:consumer, :normal)
```
"""
Expand All @@ -162,21 +162,21 @@ defmodule GenAMQP.Consumer do
@doc """
Acknowledges given message
`message` - `GenAMQP.Message` struct
`message` - `GenRMQ.Message` struct
"""
@spec ack(message :: GenAMQP.Message.t()) :: :ok
@spec ack(message :: GenRMQ.Message.t()) :: :ok
def ack(%Message{state: %{in: channel}, attributes: %{delivery_tag: tag}}) do
Basic.ack(channel, tag)
end

@doc """
Requeues / rejects given message
`message` - `GenAMQP.Message` struct
`message` - `GenRMQ.Message` struct
`requeue` - indicates if message should be requeued
"""
@spec reject(message :: GenAMQP.Message.t(), requeue :: Boolean.t()) :: :ok
@spec reject(message :: GenRMQ.Message.t(), requeue :: Boolean.t()) :: :ok
def reject(%Message{state: %{in: channel}, attributes: %{delivery_tag: tag}}, requeue \\ false) do
Basic.reject(channel, tag, requeue: requeue)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/message.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule GenAMQP.Message do
defmodule GenRMQ.Message do
@moduledoc """
Struct wrapping details of the consumed message
Expand Down
4 changes: 2 additions & 2 deletions lib/processor.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule GenAMQP.Processor do
defmodule GenRMQ.Processor do
@moduledoc """
Defines functions to implement by any AMQP processor
"""
@callback process(message :: GenAMQP.Message.t()) :: :ok | {:error, Any.t()}
@callback process(message :: GenRMQ.Message.t()) :: :ok | {:error, Any.t()}
end
Loading

0 comments on commit b344596

Please sign in to comment.