symfony - Symfony 如何将 Mercure 与 Messenger + RabbitMQ 一起使用?
问题描述
我希望将 Mercury 与 RabbitMQ 一起使用。这是我第一次使用 Mercury 和 RabbitMQ,所以我还不是很好。
这是我的位置:
我已经安装了 Mercure 和 Messenger。
Messenger.yaml
framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async: '%env(MESSENGER_TRANSPORT_DSN)%'
failed: '%env(MESSENGER_TRANSPORT_FAILED_DSN)%'
# sync: 'sync://'
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
.env:
MERCURE_PUBLISH_URL=http://localhost:3000/.well-known/mercure
MERCURE_JWT_TOKEN=aVerySecretKey
MESSENGER_TRANSPORT_DSN=amqp://bastien:mypassword@localhost:5672/%2f/messages
MESSENGER_TRANSPORT_FAILED_DSN=amqp://bastien:mypassword@localhost:5672/%2f/failed
在我的控制器中,我在本地应用程序的 URL 上模拟了 50 次 ping:
/**
* @Route("/ping", name="ping", methods={"POST"})
*/
public function ping(MessageBusInterface $bus)
{
for($i=0;$i<=50;$i++)
{
$update = new Update("http://monsite.com/ping", "[]");
$bus->dispatch($update);
}
return $this->redirectToRoute('home');
}
我已经成功启动了我的 Mercury 实例以及 Messenger 实例,因此它与我的 RabbitMQ 连接良好。
但是当我测试发送 ping 时,它可以工作,但没有通过我的 RabbitMQ。我错过了什么?我在路由部分想到了我的 Messenger.yaml,但如果是这种情况,我不知道该放什么
解决方案
默认情况下,消息在 messenger 中同步执行。
您需要在 messenger.yaml 中配置更新消息以使用异步传输:
Symfony\Component\Mercure\Update: async
推荐阅读
- ubuntu - 如何在ubuntu上格式化只读usb?
- html - 我希望斜线在两个小盒子之间
- html - 对齐图像以适合封面背景图像的区域?
- node.js - 在 Puppeteer 中将变量作为参数传递给 $eval
- python - 带有矢量文本和数值数据的决策树
- vb.net - Webforms 错误显示了两个项目,尽管解决方案显示了一个项目
- sql - 在 SQL Unpivot 中包含列名
- c# - ASP.NET Core react - 将 Okta 选项从 ASP.NET Core 传递到 ReactJS 应用程序
- python - 任意进程的python进程间互斥锁
- android - Presigned APK 在 AOSP 构建中丢失签名