RabbitMQ Integration
INTRODUCTION
REQUIREMENTS
- RabbitMQ server needs to be installed and configured.
- Drupal 8.4.0 or more recent must be configured with
php-amqplib
- go to the root directory of your site
- edit
composer.json
(notcore/composer.json
) - insert
"php-amqplib/php-amqplib": "^2.7"
in therequire
section of the file. - Optional, but recommended: insert
"ext-pcntl": "*"
in therequire
section of the file. Ensure your PHP actually includes that standard extension. Without it, the timeout mechanism for the consumer service will not be available. - Save it.
- update your
vendor
directory by typingcomposer update
.
INSTALLATION
-
Provide connection credentials as part of the
$settings
global variable insettings.local.php
(see theexample.settings.local.php
provided)$settings['rabbitmq_credentials']['default'] = [ 'host' => 'localhost', 'port' => 5672, 'vhost' => '/', 'username' => 'guest', 'password' => 'guest', ];
CONFIGURATION
- Configure RabbitMQ as the queuing system for the queues you want RabbitMQ to
maintain, either as the default queue service, default reliable queue service,
or specifically for each queue:
-
If you want to set RabbitMQ as the default queue manager, then add the following to your settings.
$settings['queue_default'] = 'queue.rabbitmq.default';
-
Alternatively you can also set for each queue to use RabbitMQ using one of these formats:
$settings['queue_service_{queue_name}'] = 'queue.rabbitmq.default'; $settings['queue_reliable_service_{queue_name}'] = 'queue.rabbitmq.default';
-
CUSTOMIZATION
Modules may override queue or exchange defaults built in a custom module by
implementing config/install/rabbitmq.config.yml
. See
src/Queue/QueueBase.php
and src/Tests/RabbitMqTestBase::setUp()
for details.
SSL
It is similar to the normal connection array, but you need to add 2 extra array keys.
This is an example of how settings.php
should look like:
$settings['rabbitmq_credentials']['default'] = [
'host' => 'host',
'port' => 5672,
'vhost' => '/',
'username' => 'guest',
'password' => 'guest',
'ssl' => [
'verify_peer_name' => false,
'verify_peer' => false,
'local_pk' => '~/.ssh/id_rsa',
],
'options' => [
'connection_timeout' => 20,
'read_write_timeout' => 20,
],
];