我使用Python kombu包与RabbitMQ的服务交互。 我想清除所有队列。 我看到有一个kombu.Queue.purge方法,但我不想创建kombu.Queue对象,因为我不知道哪些交换机连接到哪些队列。 我只想使用队列名称。 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我正在阅读这篇文章,它说在fanout
以外的消息交换中,消息被路由到与其键匹配的队列中。
如果是这样,那么为什么在以下注释中有两个参数( @Queue
value
和key
)? 仅指定队列名称还不够吗?
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = RabbitMQConfiguration.AUTHENTICATION_EMAILS_QUEUE, durable = "true"), exchange = @Exchange(value = RabbitMQConfiguration.EMAIL_MESSAGE_EXCHANGE_NAME), key = "accountActivationEmail"))
public void receiveMessage(Map<String, String> message) {
this.sendEmail(getEmail(message));
}
另一个问题:有了您为侦听器看到的注释,我是否需要有一个单独的@Configuration
类来指定MessageListenerAdapter
, SimpleMessageListenerContainer
, Binding
, Exchange
和Queue
,如下所示:
@Configuration
public class RabbitMQConfiguration {
public final static String AUTHENTICATION_EMAILS_QUEUE = "AUTHENTICATION_EMAILS_QUEUE";
public final static String EMAIL_MESSAGE_EXCHANGE_NAME = "EMAIL_EVENTS";
@Bean
public Queue authenticationEmailsQueue() {
return new Queue(AUTHENTICATION_EMAILS_QUEUE, false);
}
@Bean
public DirectExchange emailMessagesExchange() {
return new DirectExchange(EMAIL_MESSAGE_EXCHANGE_NAME);
}
@Bean
public Binding authenticationEmailMQBinding(Queue queue, DirectExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(AUTHENTICATION_EMAILS_QUEUE);
}
@Bean
public SimpleMessageListenerContainer authenticationEmailContainer(ConnectionFactory connectionFactory,
MessageListenerAdapter listenerAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(AUTHENTICATION_EMAILS_QUEUE);
container.setMessageListener(listenerAdapter);
return container;
}
@Bean
public MessageListenerAdapter authenticationEmailHandlerAdapter(AuthenticationEmailHandler receiver) {
return new MessageListenerAdapter(receiver, "receiveMessage");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.