laravel-queue-rabbitmq icon indicating copy to clipboard operation
laravel-queue-rabbitmq copied to clipboard

Laravel 6, configure arguments

Open thewasta opened this issue 3 years ago • 2 comments

This is my current configuration

....
    'connections' => [

        'rabbitmq' => [
            'driver' => 'rabbitmq',
            'worker' => env('RABBITMQ_WORKER', 'default'),
            'queue' => env('RABBITMQ_QUEUE', 'default'),
            'connection' => PhpAmqpLib\Connection\AMQPLazyConnection::class,
            'host' => env('RABBITMQ_HOST'),
            'port' => env('RABBITMQ_PORT'),
            'vhost' => env('RABBITMQ_VHOST'),
            'login' => env('RABBITMQ_LOGIN', 'guest'),
            'password' => env('RABBITMQ_PASSWORD', 'guest'),
            'options' => [
                'exchange' => [
                    'name' => env('RABBITMQ_EXCHANGE_NAME'),
                    'declare' => true,
                    'type' => env('RABBITMQ_EXCHANGE_TYPE', \Interop\Amqp\AmqpTopic::TYPE_DIRECT),
                    'passive' => env('RABBITMQ_EXCHANGE_PASSIVE', false),
                    'durable' => env('RABBITMQ_EXCHANGE_DURABLE', true),
                    'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
                    'arguments' => env('RABBITMQ_EXCHANGE_ARGUMENTS'),
                ],
                'queue' => [
                    'declare' => env('RABBITMQ_QUEUE_DECLARE', true),
                    'bind' => env('RABBITMQ_QUEUE_DECLARE_BIND', true),
                    'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),
                    'durable' => env('RABBITMQ_QUEUE_DURABLE', true),
                    'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
                    'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),
                    'arguments' => env('RABBITMQ_QUEUE_ARGUMENTS'),
                ],
            ]
        ]
    ],
....

Basically is a copy-paste from the example, now I want to add arguments to my queue and my arguments I tried with a array


'queue' => [
  'arguments' => [
    'x-message-ttl' => 6000
  ]
]

But this give the error

json_decode() expects parameter 1 to be string, array given {"exception":"[object] (ErrorException(code: 0): json_decode() expects parameter 1 to be string, array given at /var/www/vendor/vladimir-yuldashev/laravel-queue-rabbitmq/src/Queue/RabbitMQQueue.php:41)

So I decided to set it as string

'queue' => [
  'arguments' => 'x-message-ttl:6000'
]

But this error

Argument 1 passed to Interop\Amqp\Impl\AmqpQueue::setArguments() must be of the type array, null given, called in /var/www/vendor/vladimir-yuldashev/laravel-queue-rabbitmq/src/Queue/RabbitMQQueue.php on line 234 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Argument 1 passed to Interop\\Amqp\\Impl\\AmqpQueue::setArguments() must be of the type array, null given, called in /var/www/vendor/vladimir-yuldashev/laravel-queue-rabbitmq/src/Queue/RabbitMQQueue.php on line 234 at /var/www/vendor/queue-interop/amqp-interop/src/Impl/AmqpQueue.php:78)

Also I want to know how can I add arguments to my queue when dispatching job

PingJob::dispatch()->onQueue("my_second_queue");

// I want to use more than one queue, that's why I use onQueue

thewasta avatar Nov 18 '21 12:11 thewasta

@thewasta Have you found any solution?

I'm looking for something similar. I'd like to dispatch a job, but also copy the payload to another queue.

Fanout exchange seems to be the best, but not sure how to route.

talovicnedim avatar Nov 24 '21 02:11 talovicnedim

@thewasta Have you found any solution?

I'm looking for something similar. I'd like to dispatch a job, but also copy the payload to another queue.

Fanout exchange seems to be the best, but not sure how to route.

Yes! I got it, you must to use json_encode(["argument" => "value"])

thewasta avatar Nov 24 '21 07:11 thewasta

Closing due to inactivity.

M-Porter avatar Jan 25 '23 18:01 M-Porter