Symfony. Integrando el componente Messenger con RabbitMQ

Como integrar el componente Messenger con el sistema de colas RabbitMQ

Configurando Docker

Image for post
Image for post
Image for post
Image for post

Dockerfile-php

pecl install amqp
docker-php-ext-enable amqp
Image for post
Image for post

Dockerfile-php-consume

#!/usr/bin/env bashsleep 10;/var/www/rocket/bin/console messenger:consume -vv >&1;
Image for post
Image for post

Dockerfile-nginx

Image for post
Image for post
Image for post
Image for post

Dockerfile-rabbitmq

Image for post
Image for post

Estructura de carpetas

Image for post
Image for post

Ejecutar el proyecto

docker-compose up -d --build
http://localhost:8001

Componente Messenger y RabbitMQ

composer require messenger
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Image for post
Notification sent to one\nNotification sent to two\nNotification sent to three\nNotifications sent

Integrando RabbitMQ

Image for post
Image for post
amqp://guest:guest@rabbitmq:5672/%2f/messages

Revisando Rabbit

docker exec -it project_name_rabbitmq_1 bash
$ rabbitmqctl  list_queues
root@fcf3d72d0e56:/# rabbitmqctl  list_queuesTimeout: 60.0 seconds ...Listing queues for vhost / ...name messagesmessages 1
Image for post
Image for post

Consumiendo los mensajes

docker exec -it project_name_php_1 bash
bin/console messenger:consume
Notification sent to one\nNotification sent to two\nNotification sent to three
docker logs -f project-name_php-consume_1 --details
[OK] Consuming messages from transports "amqp".// The worker will automatically exit once it has received a stop signal via// the messenger:stop-workers command.
2019-09-16T10:51:28+00:00 [info] Received message App\Message\NotificationMessage2019-09-16T10:51:31+00:00 [info] Message App\Message\NotificationMessage handled by App\MessageHandler\NotificationHandler::__invoke2019-09-16T10:51:31+00:00 [info] App\Message\NotificationMessage was handled successfully (acknowledging to transport).
Image for post
Image for post

Conclusiones

¿Quieres recibir más artículos como este?

Entre paseo y paseo con Simba desarrollo en Symfony y React