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

[COART-181]: Check Gracefully termination in all our applications #211

Merged
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
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ and this project adheres to

---

## [6.1.2] - 2024-12-02

### Added

- ([#211](https://github.com/primait/amqpx/pull/211)) Allow to skip the DLK check for a
list of dead letter queues

---

## [6.1.1] - 2024-12-02

### Added
Expand Down Expand Up @@ -88,7 +97,8 @@ and this project adheres to
- ([#129](https://github.com/primait/amqpx/pull/)) Default binding for DLX
queues instead of wildcard

[Unreleased]: https://github.com/primait/amqpx/compare/6.1.1...HEAD
[Unreleased]: https://github.com/primait/amqpx/compare/6.1.2...HEAD
[6.1.2]: https://github.com/primait/amqpx/compare/6.1.1...6.1.2
[6.1.1]: https://github.com/primait/amqpx/compare/6.1.0...6.1.1
[6.1.0]: https://github.com/primait/amqpx/compare/6.0.4...6.1.0
[6.0.4]: https://github.com/primait/amqpx/compare/6.0.3...6.0.4
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM public.ecr.aws/prima/elixir:1.12.0-1
FROM public.ecr.aws/prima/elixir:1.14.2-5

WORKDIR /code

USER app

COPY ["entrypoint", "/entrypoint"]
RUN mix local.hex --force && \
mix local.rebar --force

ENTRYPOINT ["/entrypoint"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,17 @@ defmodule Myapp.HandleRejectionConsumer do
end
end
```

## Local Environment

### Test suite

In order to run the test suite, you need to startup the docker compose and jump into it with:
```
docker compose run --service-ports console bash
```

and run the test suite with:
```
mix test
```
28 changes: 21 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
version: "2"
services:
web:
console:
build: .
volumes:
- .:/$PWD
- ~/.cache:/home/app/.cache
working_dir: $PWD
links:
- rabbit
- rabbit_two
- .:/code:delegated
working_dir: /code
stdin_open: true
tty: true
command: bash
depends_on:
rabbit:
condition: service_started
rabbit_two:
condition: service_healthy

rabbit:
image: rabbitmq:3-management
Expand All @@ -18,6 +22,11 @@ services:
RABBITMQ_DEFAULT_PASS: amqpx
ports:
- "23555:15672"
healthcheck:
test: "rabbitmq-diagnostics -q ping"
interval: 10s
timeout: 5s
retries: 3

rabbit_two:
image: rabbitmq:3-management
Expand All @@ -27,3 +36,8 @@ services:
RABBITMQ_DEFAULT_PASS: amqpx
ports:
- "23556:15672"
healthcheck:
test: "rabbitmq-diagnostics -q ping"
interval: 10s
timeout: 5s
retries: 3
15 changes: 0 additions & 15 deletions entrypoint

This file was deleted.

14 changes: 13 additions & 1 deletion lib/amqp/helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Amqpx.Helper do
Helper functions
"""

require Logger

alias Amqpx.{Exchange, Queue}

def manager_supervisor_configuration(config) do
Expand Down Expand Up @@ -92,7 +94,14 @@ defmodule Amqpx.Helper do
end

def setup_dead_lettering(_channel, %{queue: dlq, exchange: "", routing_key: bad_dlq}) do
raise "If x-dead-letter-exchange is an empty string, x-dead-letter-routing-key should be '#{dlq}' instead of '#{bad_dlq}'"
msg =
"If x-dead-letter-exchange is an empty string, x-dead-letter-routing-key should be '#{dlq}' instead of '#{bad_dlq}'"

if Enum.member?(skip_dead_letter_routing_key_check_for(), bad_dlq) do
Logger.warn(msg)
else
raise msg
end
end

def setup_dead_lettering(channel, %{queue: dlq, exchange: exchange, routing_key: routing_key}) do
Expand Down Expand Up @@ -188,4 +197,7 @@ defmodule Amqpx.Helper do
start: {Amqpx.SignalHandler, :start_link, []}
}
]

defp skip_dead_letter_routing_key_check_for,
do: Application.get_env(:amqpx, :skip_dead_letter_routing_key_check_for, [])
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Amqpx.MixProject do
[
app: :amqpx,
name: "amqpx",
version: "6.1.1",
version: "6.1.2",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :production,
Expand Down
27 changes: 27 additions & 0 deletions test/helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,33 @@ defmodule HelperTest do
end
end

test "bad configuration with empty dead letter exchange and routing key is not a blocking error if the check is disabled",
meta do
queue_name = rand_name()
routing_key_name = rand_name()
exchange_name = rand_name()
wrong_dead_letter_key = rand_name()

Application.put_env(:amqpx, :skip_dead_letter_routing_key_check_for, [wrong_dead_letter_key])

:ok =
Helper.declare(meta[:chan], %{
exchanges: [
%{name: exchange_name, opts: [durable: true], routing_keys: [routing_key_name], type: :topic}
],
opts: [
durable: true,
arguments: [
{"x-dead-letter-exchange", :longstr, ""},
{"x-dead-letter-routing-key", :longstr, wrong_dead_letter_key}
]
],
queue: queue_name
})

Application.put_env(:amqpx, :skip_dead_letter_routing_key_check_for, [])
end

defp rand_name do
:crypto.strong_rand_bytes(8) |> Base.encode64()
end
Expand Down
Loading