我在symfomy4中使用rabbitmqbundle。
我想实现的是发布一条消息(在我的例子中是一个通知),然后通过路由键选择是将消息存储在数据库中,还是通过电子邮件发送,或者两者兼而有之。
我专注于
话题
交换,但我不知道如何达到这个目标,也许我不完全理解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
在这种情况下,我可以将消息发布到路由密钥之一:
通知.store
或
通知.email
我想要发布($msg,['notification.store','notification.email']),但我知道我可以
消费者
听多个路由键和通配符,但我不知道如何配置它。
这有可能吗?