Framework: Multiple Queue Connections, Amazon SQS, Laravel Cannot Push or Read to Secondary Non-Default Connection

Created on 1 Jun 2014  路  7Comments  路  Source: laravel/framework

I have the following Queue config:

    'default' => 'sqs',

    'connections' => array(

        'high' => array(
            'driver' => 'sqs',
            'key'    => 'xxx',
            'secret' => 'xxx',
            'queue'  => 'https://sqs.us-east-1.amazonaws.com/xxx/xxxx',
            'region' => 'us-east-1',

        ),

        'sqs' => array(
            'driver' => 'sqs',
            'key'    => 'xxx',
            'secret' => 'xxx',
            'queue'  => 'https://sqs.us-east-1.amazonaws.com/yyy/yyyy',
            'region' => 'us-east-1',
        ),      
    ),

This works if I am pushing with:

Queue::push('MethodName');

And listening (via supervisord) with this:

php artisan queue:listen

I have tested both connections individually and they do connect (push/read) with SQS fine.

However, when I try listening with:

php artisan queue:listen --queue=high,sqs

I get this error repeatedly in my logs when I run the listener:

Aws\Sqs\Exception\SqsException: AWS Error Type: client, AWS Error Message: 
The address high is not valid for this endpoint., User-Agent: aws-sdk-php2/2.6.5 Guzzle/3.9.1 curl/7.26.0 PHP/5.5.12-1~dotdeb.1`

So, AWS is actually seeing my connection alias named high it seems?

Also, when I try pushing to the 'high' connection with:

Queue::push('MethodName', $params, 'high');

I get the same error in my logs and the connection fails.

I have tried changing the connection names, ex high,low. I have also tried changing the queue priority order to sqs,high with the same problem.

If queue priority cannot be used I would settle for simply for having some workers dedicated to the 'high' queue and some to the 'sqs' queue. However I can't seem to find ANY way to target both, specific SQS queues with any combination of configuration.

My guess is something buggy is going on.

Most helpful comment

I just figured this out so I am hoping this will help somebody else out. SQS is different than other queue formats because the 'queue' parameter in the queue config file is actually the URL of the queue!

So to deal with it you must do the following:

Push like this:

Queue::push('MethodName', $params, 'http://path.to.sqs.queue/');

and in supervisor, run artisan:listen with:

command=php /var/www/artisan queue:listen --queue="http://path.to.sqs.queue/,http://path.to.sqs.queue-alt"

But strangely, from the command line you can also do:

php artisan queue:listen low

or

php artisan queue:listen high

So, the aliases actually work directly on the command line. Not sure why.

All 7 comments

I just figured this out so I am hoping this will help somebody else out. SQS is different than other queue formats because the 'queue' parameter in the queue config file is actually the URL of the queue!

So to deal with it you must do the following:

Push like this:

Queue::push('MethodName', $params, 'http://path.to.sqs.queue/');

and in supervisor, run artisan:listen with:

command=php /var/www/artisan queue:listen --queue="http://path.to.sqs.queue/,http://path.to.sqs.queue-alt"

But strangely, from the command line you can also do:

php artisan queue:listen low

or

php artisan queue:listen high

So, the aliases actually work directly on the command line. Not sure why.

You saved my life!!!! For all you guys having the same issue, this is the right solution coz it works for me!

2 years later, this is still a HUGE help! Please note that - at least in my case - the quotation marks around the queue path are essential. This should really be in the documentation. Thank you, @phirschybar ! :-)

+1

2018 ===> Still relevant. thank you @phirschybar

2019 still relevant. Saved our config! Thank you

No.

The correct way is to define a prefix key in the array.

'driver' => 'sqs',
'key'    => 'your-aws-key',
'secret' => 'your-aws-secret',
'queue'  => 'your-default-queue-name',
'prefix'  => 'https://sqs.us-east-1.amazonaws.com/your-account-id', // region is in there, if you are not "us-east-1" has to be changed here, too
'region' => 'us-east-1',

Laravel will then build the correct queue url.

Was this page helpful?
0 / 5 - 0 ratings