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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DLX feature for queues #1

Merged
merged 5 commits into from
Nov 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ config.neon:

```neon
extensions:
rabbitmq: Mallgroup\RabbitMQ\DI\RabbitMQExtension
rabbitmq: Bckp\RabbitMQ\DI\RabbitMQExtension
```

### Example configuration
Expand Down Expand Up @@ -47,6 +47,13 @@ rabbitmq:
# false - do not declare (will fail if not created)
# never - do not declare even if command is called, this one is mainly for no-permissions state

autoDlxQueue:
connection: default
autoCreate: true
dlx: [+5min, +15min]
# Will create automaticly 2 new dlx queues and exchanges to handle them
# if message is rejected in queue, it will go to first DLX, on second reject it will go to second DLX, on third will be throwed away

exchanges:
testExchange:
connection: default
Expand Down Expand Up @@ -111,7 +118,7 @@ rabbitmq:
# Enable tracy bar panel
tracy:
bar:
- Mallgroup\RabbitMQ\Diagnostics\BarPanel
- Bckp\RabbitMQ\Diagnostics\BarPanel
```

### Declaring Queues and Exchanges
Expand Down Expand Up @@ -154,7 +161,7 @@ services.neon:

```neon
services:
- TestQueue(@Mallgroup\RabbitMQ\Client::getProducer(testProducer))
- TestQueue(@Bckp\RabbitMQ\Client::getProducer(testProducer))
```

TestQueue.php:
Expand All @@ -164,7 +171,7 @@ TestQueue.php:

declare(strict_types=1);

use Mallgroup\RabbitMQ\Producer\Producer;
use Bckp\RabbitMQ\Producer\Producer;

final class TestQueue
{
Expand Down Expand Up @@ -196,7 +203,7 @@ final class TestQueue

Bunny does not support well producers that run a long time but send the message only once in a long period. Producers often drop connection in the middle but bunny have no idea about it (stream is closed) and if you try to write some data, an exception will be thrown about broken connection.
Drawback: you must call heartbeat by yourself.
In the example below, you can see that Connection::sendHearbeat() is callen in every single cycle - that is not a problem as internally, `Mallgroup\rabbitmq` will actually let you send the heartbeat to rabbitmq only once per 1 second.
In the example below, you can see that Connection::sendHearbeat() is callen in every single cycle - that is not a problem as internally, `Bckp\RabbitMQ` will actually let you send the heartbeat to rabbitmq only once per 1 second.

LongRunningTestQueue.php:

Expand All @@ -205,7 +212,7 @@ LongRunningTestQueue.php:

declare(strict_types=1);

use Mallgroup\RabbitMQ\Producer\Producer;
use Bckp\RabbitMQ\Producer\Producer;

final class LongRunningTestQueue
{
Expand Down Expand Up @@ -270,7 +277,7 @@ TestConsumer.php
declare(strict_types=1);

use Bunny\Message;
use Mallgroup\RabbitMQ\Consumer\IConsumer;
use Bckp\RabbitMQ\Consumer\IConsumer;

final class TestConsumer implements IConsumer
{
Expand Down Expand Up @@ -303,7 +310,7 @@ TestBulkConsumer.php
declare(strict_types=1);

use Bunny\Message;
use Mallgroup\RabbitMQ\Consumer\IConsumer;
use Bckp\RabbitMQ\Consumer\IConsumer;

final class TestConsumer
{
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: "Quality assurance"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
Expand All @@ -28,7 +28,7 @@ jobs:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
Expand All @@ -41,7 +41,7 @@ jobs:
name: Psalm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
Expand All @@ -54,13 +54,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.0', '8.1', '8.2' ]
php: [ '8.0', '8.1', '8.2', '8.3' ]

fail-fast: false

name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand All @@ -74,7 +74,7 @@ jobs:
runs-on: ubuntu-latest
needs: [tests]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ install:
qa: phpstan cs

cs:
vendor/bin/phpcs --standard=vendor/gamee/php-code-checker-rules/ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=temp -sp src
composer phpcs

csf:
vendor/bin/phpcbf --standard=vendor/gamee/php-code-checker-rules/ruleset.xml --extensions=php,phpt --tab-width=4 --ignore=temp -sp src
composer fix-style

phpstan:
vendor/bin/phpstan analyse src
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mallgroup/rabbitmq",
"name": "bckp/rabbitmq",
"description": "Nette extension for RabbitMQ (using BunnyPHP)",
"type": "library",
"license": "MIT",
Expand All @@ -26,12 +26,12 @@
],
"autoload": {
"psr-4": {
"Mallgroup\\RabbitMQ\\": "src/"
"Bckp\\RabbitMQ\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Mallgroup\\RabbitMQ\\Tests\\": "tests"
"Bckp\\RabbitMQ\\Tests\\": "tests"
}
},
"require": {
Expand Down
34 changes: 34 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: '3.3'

services:
app:
image: "trafex/php-nginx"
container_name: nette-rabbit
ports:
- "8088:80"
volumes:
- ../src.:/var/www/html
links:
- rabbitmq
depends_on:
- rabbitmq
stdin_open: true
tty: true

rabbitmq:
image: "rabbitmq:3.11.19-management"
container_name: rabbit
environment:
RABBITMQ_ERLANG_COOKIE: "uTVS3R2GmZJWN3rQ7zWM"
RABBITMQ_DEFAULT_USER: "guest"
RABBITMQ_DEFAULT_PASS: "guest"
RABBITMQ_DEFAULT_VHOST: "/"
ports:
- "15672:15672"
volumes:
- ./docker/etc/rabbitmq/enabled_plugins:/etc/rabbitmq/enabled_plugins
dns:
- 10.1.17.211
- 172.26.1.227
labels:
NAME: "rabbitmq"
2 changes: 1 addition & 1 deletion src/AbstractDataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ;
namespace Bckp\RabbitMQ;

abstract class AbstractDataBag
{
Expand Down
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ;
namespace Bckp\RabbitMQ;

use Mallgroup\RabbitMQ\Producer\Exception\ProducerFactoryException;
use Mallgroup\RabbitMQ\Producer\IProducer;
use Mallgroup\RabbitMQ\Producer\ProducerFactory;
use Bckp\RabbitMQ\Producer\Exception\ProducerFactoryException;
use Bckp\RabbitMQ\Producer\IProducer;
use Bckp\RabbitMQ\Producer\ProducerFactory;

/**
* This package uses composer library bunny/bunny. For more information,
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

class Api implements IApi
{
Expand Down
4 changes: 2 additions & 2 deletions src/Connection/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

use Bunny\Client as BunnyClient;
use Bunny\ClientStateEnum;
use Bunny\Constants;
use Bunny\Exception\BunnyException;
use Bunny\Exception\ClientException;
use Bunny\Protocol;
use Mallgroup\RabbitMQ\Connection\Exception\WaitTimeoutException;
use Bckp\RabbitMQ\Connection\Exception\WaitTimeoutException;
use Nette\Utils\Strings;
use function time;

Expand Down
4 changes: 2 additions & 2 deletions src/Connection/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

use Bunny\Channel;
use Bunny\Exception\ClientException;
use Mallgroup\RabbitMQ\Connection\Exception\ConnectionException;
use Bckp\RabbitMQ\Connection\Exception\ConnectionException;
use function in_array;
use function max;
use function time;
Expand Down
4 changes: 2 additions & 2 deletions src/Connection/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

use Mallgroup\RabbitMQ\Connection\Exception\ConnectionFactoryException;
use Bckp\RabbitMQ\Connection\Exception\ConnectionFactoryException;

final class ConnectionFactory
{
Expand Down
4 changes: 2 additions & 2 deletions src/Connection/ConnectionsDataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

use Mallgroup\RabbitMQ\AbstractDataBag;
use Bckp\RabbitMQ\AbstractDataBag;

final class ConnectionsDataBag extends AbstractDataBag
{
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Exception/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection\Exception;
namespace Bckp\RabbitMQ\Connection\Exception;

class ConnectionException extends \RuntimeException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Exception/ConnectionFactoryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection\Exception;
namespace Bckp\RabbitMQ\Connection\Exception;

class ConnectionFactoryException extends \InvalidArgumentException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Exception/PublishException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection\Exception;
namespace Bckp\RabbitMQ\Connection\Exception;

class PublishException extends ConnectionException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Connection/Exception/WaitTimeoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection\Exception;
namespace Bckp\RabbitMQ\Connection\Exception;

use Bunny\Exception\ClientException;

Expand Down
2 changes: 1 addition & 1 deletion src/Connection/IApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

interface IApi
{
Expand Down
4 changes: 2 additions & 2 deletions src/Connection/IConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Connection;
namespace Bckp\RabbitMQ\Connection;

use Bunny\Channel;
use Bunny\Exception\BunnyException;
use Bunny\Protocol\MethodFrame;
use Mallgroup\RabbitMQ\Connection\Exception\ConnectionException;
use Bckp\RabbitMQ\Connection\Exception\ConnectionException;

interface IConnection
{
Expand Down
8 changes: 4 additions & 4 deletions src/Console/Command/AbstractConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Console\Command;
namespace Bckp\RabbitMQ\Console\Command;

use Mallgroup\RabbitMQ\Consumer\ConsumerFactory;
use Mallgroup\RabbitMQ\Consumer\ConsumersDataBag;
use Mallgroup\RabbitMQ\Consumer\Exception\ConsumerFactoryException;
use Bckp\RabbitMQ\Consumer\ConsumerFactory;
use Bckp\RabbitMQ\Consumer\ConsumersDataBag;
use Bckp\RabbitMQ\Consumer\Exception\ConsumerFactoryException;
use Symfony\Component\Console\Command\Command;

abstract class AbstractConsumerCommand extends Command
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/ConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Mallgroup\RabbitMQ\Console\Command;
namespace Bckp\RabbitMQ\Console\Command;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down