3

The goal is to be able to send messages using AWS SQS+SNS. This has been a struggle for a few days and I don't know how to make it work.

Symfony 4.2 has a new component, messenger that I wanted to use. It is supposed to work with php-enqueue as a third party transport. I am using that to connect to AWS SQS+SNS.

I can't find any documentation that puts it all together. I see how php-enqueue connects to AWS, but the docs show the config in the code and not in the config yaml or .env files. That is a problem since I want Messenger/enqueue to handle the behind-the-scenes stuff.

I was able to make Symfony Messenger work without php-enqueue for local synchronous messages. But after that... Clearly I am not doing it right. I was hoping someone might have a boilerplate for this configuration.

Here is where I am at. I am just trying to send a message using SQS. I am getting an error:

Error executing "GetQueueUrl" on "https://sqs.us-west-2.amazonaws.com"; 
AWS HTTP error: Client error: `POST https://sqs.us-west-2.amazonaws.com`
resulted in a `400 Bad Request`

I tried many permutations of keys in the enqueue.yaml file but did not get it right. I used this for help but could not get it to work. https://enqueue.readthedocs.io/en/stable/bundle/config_reference/

->> Edit: I found that you can add the topic and queue names to the DSN. I no longer get the error and a topic is created, but the Queue is not. Now, the message bus is working, but synchronously and locally. No message is sent to AWS.

These are the Composer libs I installed. I am sure that there are too many, but I kept trying to make it work.

"aws/aws-sdk-php": "^3.19",
"enqueue/amqp-lib": "^0.9.8",
"enqueue/enqueue-bundle": "^0.9.8",
"enqueue/messenger-adapter": "^0.2.2",
"enqueue/snsqs": "^0.9.0",
"guzzlehttp/guzzle": "^6.0",
"symfony/amqp-pack": "^1.0",
"symfony/messenger": "4.2.*",

This is my messenger.yaml

framework:
    messenger:
        transports:
            amqp: 'enqueue://default?topic[name]=testQ&queue[name]=testQ'
        routing:
            # Route your messages to the transports
             'App\Message\SmsMessage': amqp

This is enqueue.yaml

enqueue:
    default:
        transport:
            dsn: '%env(resolve:ENQUEUE_DSN)%'
        client:~

This is the entry in .env

###> enqueue/enqueue-bundle ###
ENQUEUE_DSN=snsqs::?key={key}&secret={secret}&region=us-west-2
###< enqueue/enqueue-bundle ###

This is the code in a controller to send a message:

public function index(MessageBusInterface $messageBus) {
    $message = new SmsMessage('This is so cool');
    $messageBus->dispatch($message);
    ...
}
ScottGutman
  • 302
  • 1
  • 15
  • Did you ever get this to work? – adsc Aug 08 '19 at 08:58
  • 1
    Not yet. Still working on it. Please, let me know if you do. Symfonycasts just released their idea using doctrine which I will give a try. https://symfonycasts.com/screencast/messenger – ScottGutman Aug 09 '19 at 09:48

1 Answers1

-1

I had this same issue which i managed to fix.

This is my messenger.yaml config that's working with SQS

transports:
         sqs:
             dsn: enqueue://default?topic[name]=YOURTOPICNAME&queue[name]=YOURQUEUENAME&receiveTimeout=3

Hopefully this is of use to someone

T Heal
  • 1
  • 1