显然我已经配置了一个队列来接收我的应用程序中的用户帖子 . 以下是配置 .
<!-- Creates a queue for consumers to retrieve messages -->
<rabbit:queue name="UserPostpublishQueue" durable="true">
</rabbit:queue>
<!-- queue for sending notifications to users -->
<rabbit:queue name="notificationQueue" durable="true"/>
<!-- Fanout exchange for a pubsub bound to UserPostpublishQueue -->
<fanout-exchange name="broadcastEvents" durable="true" xmlns="http://www.springframework.org/schema/rabbit">
<bindings>
<binding queue="UserPostpublishQueue"/>
</bindings>
</fanout-exchange>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" retry-template="retryTemplate"
exchange="broadcastEvents" channel-transacted="true"/>
在代码中我只是自动装配了AMQP模板
@Autowired
AmqpTemplate amqpTemplate;
amqpTemplate.convertAndSend(post);
现在我必须引入另一个通知队列 . 我不知道该怎么做 . 我是否使用相同的扇出交换绑定队列,这样交换就会将用户的帖子推送到通知队列中 .
或者我是否创建另一个扇出交换然后将通知队列与该交换绑定,但是如何使用amqp模板注册此新交换?
或者我是否为用户发布和通知队列创建了直接交换?
我不确定 . 任何帮助,将不胜感激 .
1 回答
您应该从业务需求描述开始 .
提到的所有结合变体都是有效的 .
您真的可以再向扇出交换添加一个队列 - 同样的消息将被放置到所有队列中 . 主题行为 .
您可以创建另一个交换并在那里绑定该队列 . 在这种情况下,直接交换就足够了 . 要将消息准确地发送到该队列(可能与post不同),您应该使用不同的
AmqpTemplate
方法:也许对你来说,最好去RabbitMQ tutorials并研究所有可能的配置 .
我们最近还为这些教程添加了Spring AMQP实现到Spring AMQP Samples项目 .