13

Is there a method on the Queue class that can specify a specific connection as defined in the queue config? There's a similar option for MySql, where you can define 'mysql2', and then call:

DB::connection('mysql2')->table('etc')->get();

Is there a similar option for queues?

Something like:

Queue::connection('sqs2')->push('MyQueue', array('message' => $message));

2 Answers 2

15

Apparently I answered my own question above without even realizing it. You can have multiple queues and specify which one you want to push the message to by using a connection method.

Here's what my partial config looks like for anybody that's interested:

    'default' => 'sqs',

   'connections' => array(

    'sync' => array(
        'driver' => 'sync',
    ),

    'beanstalkd' => array(
        'driver' => 'beanstalkd',
        'host'   => 'localhost',
        'queue'  => 'default',
    ),

    'sqs' => array(
        'driver' => 'sqs',
        'key'    => 'xxxxxxxxxxxx',
        'secret' => 'yyyyyyyyyyyyyy',
        'queue'  => 'https://sqs.us-west-2.amazonaws.com/zzzzzzzzz',
        'region' => 'us-west-2',
    ),

    'sqs2' => array(
        'driver' => 'sqs',
        'key'    => 'uuuuuuuuuuuuu',
        'secret' => 'vvvvvvvvvvvvvvvv',
        'queue'  => 'https://sqs.us-west-2.amazonaws.com/wwwwwwwwwww',
        'region' => 'us-west-2',
    ),
Sign up to request clarification or add additional context in comments.

2 Comments

To make things clear, I must add that in this case you must start listener as php artisan queue:work sqs2, not php artisan queue:work --queue=sqs2. It took some time for me to realise.
As per above configuration, what would be the value of QUEUE_DRIVER from `.env' configuration? Does it really work?
5

You only configure one connection to SQS, then unlike other drivers like redis or database, if you want to send a job in a different queue name, that queue should exist previously, create it in the amazon console or with an SDK/api, then pass it when dispatching the job like this:

dispatch(new MyJob)->onConnection('sqs')->onQueue('https://sqs.us-east-1.amazonaws.com/{account_id}/{queue_name}');

In this way you only configure one connection, and have multiple queues in that connection

For last for proccesing the Job like in egekhter response,

php artisan queue:work sqs --queue='https://sqs.us-east-1.amazonaws.com/{account_id}/{queue_name}'

you also can configure multiple connections but it seems unnecessary since all of them are in the same account and credentials, and it seems the perfect use case for multiple queues in the same conexion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.