John Davidson

php - Symfony RabbitMQ Bundle in AWS (managed service): Any way to get this working?

0 comments
Message:


We really tried a lot but it still can not get the Symfony RabbitMQ bundle (https://github.com/php-amqplib/RabbitMqBundle) running in AWS (with Docker). AWS only allows AMQPS and port 5671 to be opened in the AWS managed service.


This is our current configuration in detail:


old_sound_rabbit_mq:
connections:
default:
# nevermind
secure:
url: 'amqps://%env(RABBITMQ_USER)%:%env(RABBITMQ_PASSWORD)%@%env(RABBITMQ_HOST)%:%env(RABBITMQ_PORT)%'
vhost: '%env(RABBITMQ_VHOST)%'
lazy: true
connection_timeout: 6
read_write_timeout: 6
ssl_context:
verify_peer: false
keepalive: true
heartbeat: 60
use_socket: true # default false
producers:
# use 'old_sound_rabbit_mq.[my-producer-name]_producer' service to send data.
article_create:
connection: secure
exchange_options: { name: pimcore.article.create, type: topic }
queue_options:
name: article_create

Note that we use the "url" config value because it seems like it is the only way to set AMQPS for the bundle.


The relevant parts of docker-compose.yml:


    php-fpm:
container_name: php-fpm
environment:
- RABBITMQ_HOST=my-rabbitmq # usually the docker container (otherwise localhost or server address)
- RABBITMQ_PORT=5671 # locally it seems to work with 5672
- RABBITMQ_USER=user
- RABBITMQ_PASSWORD=password
- RABBITMQ_VHOST=/
rabbitmq:
container_name: my-rabbitmq
image: rabbitmq:3.8-management
ports:
- 127.0.0.1:15672:15672
- 127.0.0.1:5672:5672
- 127.0.0.1:5671:5671
environment:
- RABBITMQ_DEFAULT_USER=pimcore
- RABBITMQ_DEFAULT_PASS=pimcore
volumes:
- rabbitmq:/var/lib/rabbitmq

This is how the messages are sent from a Symfony Event Listener:


            $this->appKernel->getContainer()->get('old_sound_rabbit_mq.article_create_producer')->publish(
serialize($objToSend),
"article_create",
[
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
'message_id' => md5(uniqid("prefix", true))
]
);

It all seems to work locally without any issues. In AWS we get the following errors:


Without sockets:


Broken pipe or closed connection


With sockets:


[2021-06-08 15:59:45] request.CRITICAL: Uncaught PHP Exception ErrorException: "Warning: socket_recv(): unable to read from socket [104]: Connection reset by peer" at /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/SocketIO.php line 121 {"exception":"[object] (ErrorException(code: 0): Warning: socket_recv(): unable to read from socket [104]: Connection reset by peer at /var/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Wire/IO/SocketIO.php:121)"} []


My Answer:
host:
port: 5671
user:
password:
vhost: /
lazy: true
connection_timeout: 3
read_write_timeout: 3
ssl_options:
ssl_on: true
verify_peer: false
verify_peer_name: false
allow_self_signed: true

Unfortunately, the Symfony RabbitMQ Bundle does not support AMQPS and port 5671 out of the box. You may need to look into alternative solutions such as using a different RabbitMQ client library that supports AMQPS or setting up a reverse proxy to handle the SSL termination before forwarding the requests to the RabbitMQ server.

Alternatively, you could also consider using a different messaging service that is fully supported by AWS, such as Amazon SQS or Amazon SNS. These services are fully managed by AWS and do not require any additional configuration for SSL connections.

Rate this post

3 of 5 based on 3184 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us