Skip to content

Commit

Permalink
format (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpiemontese authored Nov 29, 2024
1 parent eb9dda4 commit 9c627e2
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 60 deletions.
28 changes: 14 additions & 14 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
ignore:
- dependency-name: ex_doc
versions:
- 0.23.0
- 0.24.0
- 0.24.1
- dependency-name: credo
versions:
- 1.5.4
- package-ecosystem: mix
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
ignore:
- dependency-name: ex_doc
versions:
- 0.23.0
- 0.24.0
- 0.24.1
- dependency-name: credo
versions:
- 1.5.4
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: '24'
elixir-version: '1.13'
otp-version: "25"
elixir-version: "1.14"
- name: Checkout
uses: actions/checkout@v3
- name: setup hex
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
steps:
- uses: erlef/setup-beam@v1
with:
elixir-version: 1.13
otp-version: 24
elixir-version: 1.14
otp-version: 25

# Check out the code.
- name: Checkout
Expand All @@ -30,7 +30,6 @@ jobs:
127.0.0.1 rabbit_two
" | sudo tee /etc/hosts
# Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: cache-deps
Expand Down Expand Up @@ -108,7 +107,7 @@ jobs:
- ci
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
4 changes: 2 additions & 2 deletions .github/workflows/retire.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: '24'
elixir-version: '1.13'
otp-version: "25"
elixir-version: "1.14"
- run: echo "Attempting to retire version $VERSION"
- run: mix hex.config api_key "$HEX_AUTH_KEY"
env:
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 25.3.2.8
elixir 1.13.4-otp-25
elixir 1.14.5-otp-25
40 changes: 27 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

Expand All @@ -13,27 +14,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- ([#208](https://github.com/primait/amqpx/pull/208)) Introduces the possibility of configuring a signal handler which can be used for graceful termination. When the SIGTERM arrive, we cancel all the consumer to stop taking new messages.
- ([#208](https://github.com/primait/amqpx/pull/208)) Introduces the possibility
of configuring a signal handler which can be used for graceful termination.
When the SIGTERM arrive, we cancel all the consumer to stop taking new
messages.

### Changed

- Minimum supported Elixir version is now 1.14

---

## [6.0.4] - 2024-09-02

### Added

- ([#199](https://github.com/primait/amqpx/pull/199)) `host` param will be resolved to a list of `ip`s, if it's a
hostname, and the connection will be established to the first available one.
- ([#199](https://github.com/primait/amqpx/pull/199)) `host` param will be
resolved to a list of `ip`s, if it's a hostname, and the connection will be
established to the first available one.

---

## [6.0.3] - 2024-05-28

### Fixed

- ([#190](https://github.com/primait/amqpx/pull/191)) Suppress noisy error logs at GenServer shutdown.
- ([#191](https://github.com/primait/amqpx/pull/190)) GenServer now trap exit and gracefully shutdown instead of force
the process to exit.

- ([#190](https://github.com/primait/amqpx/pull/191)) Suppress noisy error logs
at GenServer shutdown.
- ([#191](https://github.com/primait/amqpx/pull/190)) GenServer now trap exit
and gracefully shutdown instead of force the process to exit.

---

Expand All @@ -49,21 +58,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- ([#138](https://github.com/primait/amqpx/pull/138)) Add proper shutdown handling to Amqpx generic producers and consumers
- ([#121](https://github.com/primait/amqpx/pull/121)) Add retry mechanism for publish
- ([#138](https://github.com/primait/amqpx/pull/138)) Add proper shutdown
handling to Amqpx generic producers and consumers
- ([#121](https://github.com/primait/amqpx/pull/121)) Add retry mechanism for
publish

### Changed

- ([#119](https://github.com/primait/amqpx/pull/119)) Print stacktrace when rescuing exceptions
- ([#131](https://github.com/primait/amqpx/pull/131)) Refactor declare function in helper module
- ([#119](https://github.com/primait/amqpx/pull/119)) Print stacktrace when
rescuing exceptions
- ([#131](https://github.com/primait/amqpx/pull/131)) Refactor declare function
in helper module

---

## [6.0.0] - 2022-12-21

### Added

- ([#129](https://github.com/primait/amqpx/pull/)) Default binding for DLX queues instead of wildcard
- ([#129](https://github.com/primait/amqpx/pull/)) Default binding for DLX
queues instead of wildcard

[Unreleased]: https://github.com/primait/amqpx/compare/6.1.0...HEAD
[6.1.0]: https://github.com/primait/amqpx/compare/6.0.4...6.1.0
Expand Down
52 changes: 32 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

## About

A simple Amqp library based on [official elixir amqp client](https://hex.pm/packages/amqp)
Written to prevent duplicated and boilerplate code to handle all the lifecycle of the amqp connection. Write your publisher or consumer and forget about the rest!
A simple Amqp library based on
[official elixir amqp client](https://hex.pm/packages/amqp) Written to prevent
duplicated and boilerplate code to handle all the lifecycle of the amqp
connection. Write your publisher or consumer and forget about the rest!

## Installation

Expand All @@ -18,10 +20,14 @@ def deps do
end
```

From 3.0.0 Amqpx is no longer an application. This is so the client can choose in which environment or configuration to have consumers up and running.
You would then need to start your consumers and producer in the client's supervision tree, instead of adding Amqpx to the `extra_application` list as it was in the past.
From 3.0.0 Amqpx is no longer an application. This is so the client can choose
in which environment or configuration to have consumers up and running. You
would then need to start your consumers and producer in the client's supervision
tree, instead of adding Amqpx to the `extra_application` list as it was in the
past.

To start all consumers and producer inside your application, using the library helper function:
To start all consumers and producer inside your application, using the library
helper function:

```elixir
defmodule Application do
Expand Down Expand Up @@ -121,16 +127,11 @@ Default parameters:
- publish_timeout: 1_000
- backoff: 5_000 (connection retry)
- exchanges: []
- publish_retry_options: [
max_retries: 0,
retry_policy: [],
backoff: [
base_ms: 10,
max_ms: 10_000
]
]
- publish_retry_options: [ max_retries: 0, retry_policy: [], backoff: [ base_ms:
10, max_ms: 10_000 ] ]

You can also declare exchanges from the producer module, simply specify them in the configuration. There is an example below.
You can also declare exchanges from the producer module, simply specify them in
the configuration. There is an example below.

```elixir
config :myapp, :producer, %{
Expand All @@ -141,16 +142,22 @@ config :myapp, :producer, %{
]
}
```

#### Publish retry options

- `max_retries`: number of times a `publish` will be retried. A `publish` can be executed at most (`max_retries` + 1) times
- `retry_policy`: collection of error conditions which will cause the `publish` to be retried. Can be a combination of the following atoms:
- `max_retries`: number of times a `publish` will be retried. A `publish` can be
executed at most (`max_retries` + 1) times
- `retry_policy`: collection of error conditions which will cause the `publish`
to be retried. Can be a combination of the following atoms:
- `:on_publish_rejected` (when the broker itself rejects)
- `:on_confirm_timeout` (when the confirm from the broker times out)
- `:on_publish_error` (when there is an error returned at AMQP protocol level)
- `backoff`: sleep time between `publish` retries. Calculated as `random_between(0, min(cap, base * 2 ** attempt))`
- `base_ms`: time in millisecond that is used as `base` term in the formula above
- `max_ms`: time in millisecond that is used as `cap` term in the formula above
- `backoff`: sleep time between `publish` retries. Calculated as
`random_between(0, min(cap, base * 2 ** attempt))`
- `base_ms`: time in millisecond that is used as `base` term in the formula
above
- `max_ms`: time in millisecond that is used as `cap` term in the formula
above

## Usage example

Expand Down Expand Up @@ -198,7 +205,12 @@ end

## Handle message rejections

You can define an implement an optional callback inside your `Consumer` module that will be called whenever an error is raised in the `handle_message` callback and the `redelivered` flag is set to `true`. This callback can be useful whenever you want to define a standard rejection logic (e.g. datadog alarms and such).
You can define an implement an optional callback inside your `Consumer` module
that will be called whenever an error is raised in the `handle_message` callback
and the `redelivered` flag is set to `true`. This callback can be useful
whenever you want to define a standard rejection logic (e.g. datadog alarms and
such).

### Consumer

```elixir
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Amqpx.MixProject do
app: :amqpx,
name: "amqpx",
version: "6.1.0",
elixir: "~> 1.7",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :production,
deps: deps(),
Expand Down

0 comments on commit 9c627e2

Please sign in to comment.