首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Mercure与Messenger + RabbitMQ?

如何使用Mercure与Messenger + RabbitMQ?
EN

Stack Overflow用户
提问于 2020-12-02 13:57:08
回答 1查看 719关注 0票数 0

我期待使用水星与RabbitMQ。这是我第一次使用水星以及RabbitMQ,所以我还不是很好。

以下是我的处境:

我安装了Mercure和Messenger。

Messenger.yaml

代码语言:javascript
复制
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

代码语言:javascript
复制
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个页面:

代码语言:javascript
复制
    /**
     * @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');
    }

我已经成功地启动了我的水星以及信使的实例,因此它与我的RabbitMQ连接得很好。

但是,当我测试发送pings时,它可以工作,但不需要通过我的RabbitMQ。我错过了什么吗?我在路由部分想到了我的Messenger.yaml,但如果是这样的话,我不知道该怎么写

EN

回答 1

Stack Overflow用户

发布于 2020-12-03 09:30:58

默认情况下,消息在信使中同步执行。

您需要配置messenger.yaml中的更新消息以使用异步传输:

代码语言:javascript
复制
Symfony\Component\Mercure\Update: async
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65109544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档