Reputation: 1838
I'm working on Laravel 5.1.46 (LTS) with rabbitmq for message queues with package
.env
QUEUE_DRIVER=rabbitmq
config/queue.php
'rabbitmq' => [
'driver' => 'rabbitmq',
'host' => env('RABBITMQ_HOST', '127.0.0.1'),
'port' => env('RABBITMQ_PORT', 5672),
'vhost' => env('RABBITMQ_VHOST', '/'),
'login' => env('RABBITMQ_LOGIN', 'guest'),
'password' => env('RABBITMQ_PASSWORD', 'guest'),
// name of the default queue,
'queue' => env('RABBITMQ_QUEUE'),
// create the exchange if not exists
'exchange_declare' => true,
// create the queue if not exists and bind to the exchange
'queue_declare_bind' => true,
'queue_params' => [
'passive' => false,
'durable' => true, // false
'exclusive' => false,
'auto_delete' => false,
],
'exchange_params' => [
// more info at http://www.rabbitmq.com/tutorials/amqp-concepts.html
'type' => env('RABBITMQ_EXCHANGE_TYPE', 'direct'),
'passive' => false,
// the exchange will survive server restarts
'durable' => true, // fakse
'auto_delete' => false,
]
I've 8 queues in total. Queue names are stored in .env file.
QUEUE_ONE=queue-one
QUEUE_TWO=queue-two
.
.
.
QUEUE_EIGHT=queue-eight
And while dispatching a job,
dispatch(new Job1())->onQueue(env('QUEUE_ONE'))
Queues and messages are persistent/durable.
Due to some performance issues, I need to change the durability of some queues and their messages. So,
How it is possible with-in Laravel and rabbitmq ?
Note : I know, I can set
durable = false
but it will be for all queues,
Upvotes: 0
Views: 1356
Reputation: 604
// config/queue.php
'rabbitmq_durable' => [
'driver' => 'rabbitmq',
// ...
'queue_params' => [
'passive' => false,
'durable' => true,
'exclusive' => false,
'auto_delete' => false,
],
// ...
],
'rabbitmq_not_durable' => [
'driver' => 'rabbitmq',
// ...
'queue_params' => [
'passive' => false,
'durable' => false,
'exclusive' => false,
'auto_delete' => false,
],
// ...
]
Laravel 5.1
To use different configs and different connections on Laravel 5.1 you have to use the Queue
fascade:
Queue::connection('rabbitmq_durable')->pushOn('queue_1', TestJob::class);
Queue::connection('rabbitmq_not_durable')->pushOn('queue_6', TestJob::class);
Laravel 5.2+
To use different configs and different connections on Laravel 5.2 and onwards you can use the onConnection()
method like so:
TestJob::dispatch()->onQueue('queue_one')->onConnection('rabbitmq_durable');
TestJob::dispatch()->onQueue('queue_six')->onConnection('rabbitmq_not_durable');
Upvotes: 2