RabbitMQ:如何指定要发布的队列? [英] RabbitMQ: How to specify the queue to publish to?

查看:188
本文介绍了RabbitMQ:如何指定要发布的队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RabbitMQ的频道#basicConsume 方法为我们提供以下参数:

RabbitMQ's Channel#basicConsume method gives us the following arguments:

channel.basicConsume(queueName, autoAck, consumerTag, noLocal,
    exclusive, arguments, callback);

让我们能够告诉RabbitMQ我们想要使用哪个队列。

Giving us the ability to tell RabbitMQ exactly which queue we want to consume from.

但是频道#basicPublish 没有这样的等价物:

But Channel#basicPublish has no such equivalency:

channel.basicPublish(exchangeName, routingKey, mandatory, immediateFlag,
    basicProperties, messageAsBytes);

为什么我不能指定要发布到这里的队列?!? 如何将频道发布到名为的队列谢谢提前!

Why can't I specify the queue to publish to here?!? How do I get a Channel publishing to, say, a queue named logging? Thanks in advance!

推荐答案

基本上,队列可以基于routingKeys绑定到交换机。

Basically queues can be binded to an exchange based on routingKeys.

假设您有3个不同的发布者。

Publisher1发送消息与routingKey交换events

Publisher2发送消息与routingKey交换任务

发布者3发送消息与routingKey交换工作

Assume that you have 3 different publishers.
Publisher1 sending message to exchange with routingKey "events"
Publisher2 sending message to exchange with routingKey "tasks"
Publisher3 sending message to exchange with routingKey "jobs"

你可以有一个只使用特定routhingKey消息的消费者。

例如,为了让消费者获得事件消息,你就像这样声明

You can have a consumer that consumes only messages with specific routhingKey.
For example in order to have a consumer for "events" messages you declare like this

 channel.queueBind(queueName, exchangeName, "events");

如果您想要消费所有来自交易所的消息,您可以将路由指定为#

If you want to consume all the messages coming to the exchange you give the routing as '#'

所以简而言之,我可以说是,b $ b $ 1.信息将发布到交易所。

2 。队列将基于routingKeys进行交换。

3. RabbitMQ会将带有匹配路由密钥的消息转发到相应的队列。

So in short what i can say is,
1. Messages will be published to an exchange.
2. Queues will be bound to exchange based on routingKeys.
3. RabbitMQ will forward messages with matching routing keys to the corresponding queues.

请请参阅教程 - http://www.rabbitmq.com/tutorials/tutorial-three -java.html

Please see the tutorial - http://www.rabbitmq.com/tutorials/tutorial-three-java.html

RabbitMQ中消息模型的核心思想是生产者永远不会将任何消息直接发送到队列。实际上,生产者通常甚至不知道消息是否会被传递到任何队列。相反,制作人只能向交易所发送消息

这篇关于RabbitMQ:如何指定要发布的队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆