RabbitMQ 是否有信息优先的概念? 我有一个问题,一些更重要的信息由于在队列中排在队列前的重要信息不那么重要而正在减慢。 我希望高度优先的信息优先优先, 并移到队列前方 。
我知道我可以用两个队列来比较, 一个“快”队列和一个“慢”队列, 但是这看起来像一个黑客。
有谁知道用兔子兔号 更好的解决办法吗?
RabbitMQ 是否有信息优先的概念? 我有一个问题,一些更重要的信息由于在队列中排在队列前的重要信息不那么重要而正在减慢。 我希望高度优先的信息优先优先, 并移到队列前方 。
我知道我可以用两个队列来比较, 一个“快”队列和一个“慢”队列, 但是这看起来像一个黑客。
有谁知道用兔子兔号 更好的解决办法吗?
这个问题的答案是过时的。正如RabbitMQ 3. 5.0一样,现在对AMQP标准的人均邮件优先事项提供了核心支持。文件有所有详细信息,但简而言之:
更有意思的警告在医生的书里 很值得阅读
兔子除了布赖恩简洁地说,前面的兔子首先到达那里之外,别无优先的概念。
我建议实施一组队列, 以满足您特别的信息需求, 并让这些队列模式成为您的优先排序需求, 例如称它们为 MyQuueP1、 MyQuueP2 等, 然后让我们的消费者在 P2 (etc) 之前检查 P1, 并从 P2 (etc) 和 P2 (etc) 处查询服务信息 。
如果您有高优先级信息, 请通过合适的路由键和voila, 将其发布到合适的优先排队 。
[update] Check this question: In a FIFO Qeueing system, what s the best way the to implement priority messaging
[update] As per recent RabbitMQ release 3.5.0 this answer is now outdated and should be considered valid for only versions prior to this release. https://stackoverflow.com/a/29068288/489888
IRC RabbitMQ 仍然使用AMQP 协议版本0.9.1 (请查看 http://www.amqp.org/creditation/0-9-1/amqp-org-download>here )。
Messages may have a priority level. A high priority message is sent ahead of lower priority messages
waiting in the same message queue. When messages must be discarded in order to maintain a specific
service quality level the server will first discard low-priority messages.
并且:
Note that in the presence of multiple readers from a queue, or client transactions, or use of priority fields,
or use of message selectors, or implementation-specific delivery optimisations the queue MAY NOT
exhibit true FIFO characteristics.
标本上说优先是必须的 所以我猜兔子Q应该执行它 但你可能想查阅它的文件
是的, RabbitMQ 支持优先队列 。
要将队列工作作为优先队列,请在宣布队列时提供属性 x-max-rime
。
属性 x-max-max-riority
定义了队列支持的最大优先号 。
在爪哇,你可以做如下:
Map<String, Object> props = new HashMap<>();
props.put("x-max-priority", 10); // max priority number as 10
channel.queueDeclare(QUEUE_NAME, durable, false, false, props);
发布特定优先信息,请如下:
String message = "My message with priority 7";
AMQP.BasicProperties.Builder basicProps = new AMQP.BasicProperties.Builder();
basicProps.contentType("text/plain")
.priority(7);
channel.basicPublish("", QUEUE_NAME, basicProps.build(), message.getBytes());
以下是一个 C# 代码样本, 用于定义包含一系列优先级的队列 :
using RabbitMQ.Client;
public void Setup()
{
ConnectionFactory factory = new() { host = "", username = "", password = "" };
var connection = factory.CreateConnection();
var model = connection.CreateModel();
var args = new Dictionary<string, object>
{
{ "x-min-priority", 0 },
{ "x-max-priority", 9 }
};
model.QueueDeclare("Queue1", arguments: args);
}
在此设定一条发送消息优先的函数 :
private static void Send(IModel model, string queue, string message, byte priority)
{
var body = Encoding.UTF8.GetBytes(message);
var basicProperties = model.CreateBasicProperties();
basicProperties.Priority = priority;
model.BasicPublish(exchange: "",
routingKey: queue,
basicProperties: basicProperties,
body: body);
}
正如其他人提到的那样,兔子不严格遵守这些优先事项。
如果您在为队列定义的范围以外发送信件,则该信件作为最小值或最大值处理。
For any given queue, the maximum length (of either type) can be defined using a policy (this option is highly recommended) or by clients using the queue s optional arguments. In the case where both ...
I m looking to implement RabbitMQ into my PHP application, and am using the php-amqp extension. My only question is this, how do I easily query to return the contents of the queue in PHP? php-amqp ...
I d like to make sure that my message was delivered to a queue. To do so I m adding the mandatory param to the basic_publish. What else should I do to receive the basic.return message if my message ...
I d like to use AMQP to join two services one written in C# and other written in python. I m expecting quite large volume of messages per second. Is there any AMQP Broker that is production ready? ...
I m attempting to follow the celery tutorial, but I run into a problem when I run python manage.py celeryd: my RabbitMQ server (installed on a virtual machine on my dev box) won t let my user login. ...
Is it possible to make multiple consumers to share one single queue in RabbitMQ? I am currently using this php library to work with RabbitMQ, from what I observe, although I have 2 identical instances ...
as opposed to writing your own library. We re working on a project here that will be a self-dividing server pool, if one section grows too heavy, the manager would divide it and put it on another ...
I m using py-amqplib to access RabbitMQ in Python. The application receives requests to listen on certain MQ topics from time to time. The first time it receives such a request it creates an AMQP ...