mm1492
mm1492

Reputation: 33

Why Laravel uses the default queue connection even if I specified a queue with different connection

I have problem with laravel queues. In my project, default connection is sync, I want to add sqs connection for one type of jobs.

When I dispatch job in this way:

TestAction::dispatch()->onQueue('test');

Job is performed immediately (by sync connection).

If I dispatch job in this way:

TestAction::dispatch()->onQueue('test')->onConnection('sqsTestAction');

everything is ok.

Queue "test" is in sqsTestAction connection, why in first example job is being sent by sync connection?

My config/queue.php:


    'default' => env('QUEUE_CONNECTION', 'sync'),


    'connections' => [

        'sync' => [
            'driver' => 'sync',
        ],

        'sqsTestAction' => [
            'driver' => 'sqs',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'prefix' => env('AWS_SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
            'queue' => "test",
            'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
        ],

    ],

Laravel ver 5.8

Upvotes: 3

Views: 2179

Answers (1)

Tpojka
Tpojka

Reputation: 7111

why in first example job is being sent by sync connection?

Because it is set by default as you can see. Change .env file value for QUEUE_CONNECTION to sqsTestAction and that will become default. In default key of config/queue file, second parameter is fallback parameter for case when .env value doesn't exist.

Upvotes: 1

Related Questions