【发布时间】:2018-08-14 15:02:24
【问题描述】:
我在 Symfomy4 中使用 RabbitMqBundle。
我想要实现的是发布一条消息(在我的情况下是一条通知)并通过路由键选择是将消息存储在 Db 中还是通过电子邮件发送或两者兼而有之。
我专注于主题交流,但我不知道如何达到这个目标,也许我没有完全理解RabbitMQ的机制,但我对它完全陌生.
这是我的配置
old_sound_rabbit_mq:
connections:
default:
#url: '%env(RABBITMQ_URL)%'
url: 'amqp://guest:guest@localhost:5672'
vhost: '/'
lazy: false
connection_timeout: 3
read_write_timeout: 3
producers:
notifications:
connection: default
exchange_options: {name: 'notifications', type: topic}
consumers:
store_notifications:
connection: default
exchange_options: {name: 'notifications', type: topic}
queue_options:
name: 'notifications'
routing_keys:
- 'notification.store'
# - 'notification.*' # this will match everything
callback: App\Consumer\Notification\DbHandler
email_notifications:
connection: default
exchange_options: {name: 'notifications', type: topic}
queue_options:
name: 'notifications'
routing_keys:
- 'notification.email'
callback: App\Consumer\Notification\EmailHandler
在这种情况下,我可以只向其中一个路由键发布消息:notification.store 或 notification.email
我想要发布($msg,['notification.store','notification.email'])之类的东西,但我知道我可以让消费者监听多个路由键并使用通配符,但我不知道如何配置它。
这可能吗?
【问题讨论】: