rabbitmq 将消息分派到Symfony 4和Messenger中的不同传输或虚拟主机

vtwuwzda  于 2022-11-08  发布在  RabbitMQ
关注(0)|答案(1)|浏览(167)

我需要根据消息中的参数“host”将消息分派到不同的vhost/transport。是否可以在Symfony 4的标准Messenger组件中执行此操作。*?我在每台服务器上都有工作机,并且所有工作机都连接到具体的vhost。

framework:
    messenger:
        serializer:
            default_serializer: messenger.transport.symfony_serializer
            symfony_serializer:
                format: json
                context: { }
        transports:
            wendy:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%/server-wendy'
                options:
                    exchange:
                        name: wendy
                        type: direct
                    queues:
                        virtual_hosts:
                            durable: 1
                            binding_keys: ['virtual_hosts']
                        ftp:
                            durable: 1
                            binding_keys: ['ftp']
            stan:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%/server-stan'
                options:
                    exchange:
                        name: stan
                        type: direct
                    queues:
                        virtual_hosts:
                            durable: 1
                            binding_keys: ['virtual_hosts']
                        ftp:
                            durable: 1
                            binding_keys: ['ftp']

        routing:
            # Route your messages to the transports
            'App\Message\VirtualHostNotification': [wendy, stan]

例如:

$this->messageBus->dispatch(
    new VirtualHostNotification($virtualHost),
    [new AmqpStamp('wendy.virtual_hosts', AMQP_NOPARAM)],
    $transport,
    $vhost
);
q5iwbnjs

q5iwbnjs1#

添加“vhost”变量。例如:

wendy:
            dsn: '%env(MESSENGER_TRANSPORT_DSN)%/server-wendy'
            options:
                vhost: '%env(MESSENGER_TRANSPORT_VHOST)%'
                exchange:
                    name: wendy
                    type: direct
                queues:
                    virtual_hosts:
                        durable: 1
                        binding_keys: ['virtual_hosts']
                    ftp:
                        durable: 1
                        binding_keys: ['ftp']

相关问题