显然,我配置了一个队列,用于在我的应用程序中接收用户的帖子。下面是配置。
<!-- 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);现在我必须介绍另一个通知队列。我不知道该怎么做。我是否将队列绑定到相同的扇出交换中,这样做是将用户的post推送到通知队列中。
或者我是否创建了另一个扇出交换&然后将通知队列绑定到该交换,但是如何使用amqp模板注册这个新的交换呢?
还是为用户post和通知队列创建直接交换?
我不确定。任何帮助都将不胜感激。
发布于 2015-12-09 00:11:30
您应该从业务需求描述开始。
中提到的所有绑定变体都是有效的。
AmqpTemplate方法:
空convertAndSend(String exchange,String routingKey,Object message)抛出AmqpException;也许对您来说,最好去RabbitMQ 教程并研究所有可能的配置。
我们最近还为这些教程向弹簧AMQP样品项目添加了Spring实现。
https://stackoverflow.com/questions/34162070
复制相似问题