我希望将Mercury与RabbitMQ一起使用。这是我第一次使用Mercury和RabbitMQ,所以我还不好。
我在这里:
我已经安装了Mercure和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
# 'AppMessageYourMessage': 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中同步执行。
您需要在messenger.yaml中配置Update消息,以使用异步传输:
SymfonyComponentMercureUpdate: async