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

PPF-192 enable/disable delay via config #347

Merged
merged 3 commits into from
Oct 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ protected function registerCommands()
$consoleApp = $this['console'];

$consoleApp->add(new CacheClearCommand());
$consoleApp->add(new ConsumeCommand('projectaanvraag:consumer', 'rabbit.connection', 'rabbit.consumer'));

$disableDelay = $this['config']['rabbitmq']['disable_delay'] ?? false;
$consoleApp->add(new ConsumeCommand('projectaanvraag:consumer', 'rabbit.connection', 'rabbit.consumer', $disableDelay));

// Sync culturefeed consumers with local DB
$consoleApp->add(new SyncConsumersCommand());
Expand Down
38 changes: 25 additions & 13 deletions app/Core/MessageBusProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,31 @@ public function register(Container $pimple)

$pimple['publisher'] = function (Container $pimple) {
$producer = new Producer($pimple['rabbit.connection']);
$producer->setExchangeOptions(
[
'declare' => true,
'name' => 'main_exchange',
'type' => 'x-delayed-message',
'durable' => true,
'arguments' => new AMQPTable(
[
'x-delayed-type' => 'direct',
]
),
]
);
$disableDelay = $pimple['config']['rabbitmq']['disable_delay'] ?? false;
if (!$disableDelay) {
$producer->setExchangeOptions(
[
'declare' => true,
'name' => 'main_exchange',
'type' => 'x-delayed-message',
'durable' => true,
'arguments' => new AMQPTable(
[
'x-delayed-type' => 'direct',
]
),
]
);
} else {
$producer->setExchangeOptions(
[
'declare' => true,
'name' => 'main_exchange',
'type' => 'topic',
'durable' => true,
]
);
}

$producer->setQueueOptions(
[
Expand Down
15 changes: 13 additions & 2 deletions src/Console/Command/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ class ConsumeCommand extends Command
*/
protected $connectionId;

/**
* @var boolean
*/
protected $disableDelay;

/**
* ConsumeCommand constructor.
* @param null|string $name
* @param $connectionId
* @param $consumerId
* @param bool $disableDelay
*/
public function __construct($name, $connectionId, $consumerId)
public function __construct($name, $connectionId, $consumerId, $disableDelay = false)
{
parent::__construct($name);
$this->connectionId = $connectionId;
$this->consumerId = $consumerId;
$this->disableDelay = $disableDelay;
}

/**
Expand Down Expand Up @@ -73,7 +80,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$channel = $connection->channel();

// Declare the exchange
$channel->exchange_declare('main_exchange', 'x-delayed-message', false, true, false, false, false, new AMQPTable(['x-delayed-type' => 'direct']));
if (!$this->disableDelay) {
$channel->exchange_declare('main_exchange', 'x-delayed-message', false, true, false, false, false, new AMQPTable(['x-delayed-type' => 'direct']));
} else {
$channel->exchange_declare('main_exchange', 'topic', false, true, false);
}

// Declare the main queue
$channel->queue_declare('projectaanvraag', false, true, false, false, false, new AMQPTable(['routing_keys' => ['asynchronous_commands']]));
Expand Down
Loading