<bdo id='L3YOA'></bdo><ul id='L3YOA'></ul>
    1. <i id='L3YOA'><tr id='L3YOA'><dt id='L3YOA'><q id='L3YOA'><span id='L3YOA'><b id='L3YOA'><form id='L3YOA'><ins id='L3YOA'></ins><ul id='L3YOA'></ul><sub id='L3YOA'></sub></form><legend id='L3YOA'></legend><bdo id='L3YOA'><pre id='L3YOA'><center id='L3YOA'></center></pre></bdo></b><th id='L3YOA'></th></span></q></dt></tr></i><div id='L3YOA'><tfoot id='L3YOA'></tfoot><dl id='L3YOA'><fieldset id='L3YOA'></fieldset></dl></div>

      <tfoot id='L3YOA'></tfoot>
    2. <small id='L3YOA'></small><noframes id='L3YOA'>

        <legend id='L3YOA'><style id='L3YOA'><dir id='L3YOA'><q id='L3YOA'></q></dir></style></legend>
      1. RabbitMQ 3.5 和消息优先级

        时间:2023-08-24

      2. <tfoot id='fqvlw'></tfoot>
          <bdo id='fqvlw'></bdo><ul id='fqvlw'></ul>
            <tbody id='fqvlw'></tbody>

            <i id='fqvlw'><tr id='fqvlw'><dt id='fqvlw'><q id='fqvlw'><span id='fqvlw'><b id='fqvlw'><form id='fqvlw'><ins id='fqvlw'></ins><ul id='fqvlw'></ul><sub id='fqvlw'></sub></form><legend id='fqvlw'></legend><bdo id='fqvlw'><pre id='fqvlw'><center id='fqvlw'></center></pre></bdo></b><th id='fqvlw'></th></span></q></dt></tr></i><div id='fqvlw'><tfoot id='fqvlw'></tfoot><dl id='fqvlw'><fieldset id='fqvlw'></fieldset></dl></div>
              • <small id='fqvlw'></small><noframes id='fqvlw'>

                <legend id='fqvlw'><style id='fqvlw'><dir id='fqvlw'><q id='fqvlw'></q></dir></style></legend>
                1. 本文介绍了RabbitMQ 3.5 和消息优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  RabbitMQ 3.5 现在支持消息优先级;但是,我无法构建一个工作示例.我把我的代码放在下面.它包括我期望的输出和我实际的输出.我会对更多文档和/或工作示例感兴趣.

                  RabbitMQ 3.5 now supports message priority; However, I am unable to build a working example. I've placed my code below. It includes the output that I expect and the output I actually. I'd be interested in more documentation, and/or a working example.

                  简而言之,我的问题是:如何在 Rabbit 3.5.0.0 中获得消息优先级?

                  So my question in short: How do I get message priority to work in Rabbit 3.5.0.0?

                  出版商:

                  using System;
                  using RabbitMQ.Client;
                  using System.Text;
                  using System.Collections.Generic;
                  
                  class Publisher
                  {
                  
                      public static void Main()
                      {
                          var factory = new ConnectionFactory() { HostName = "localhost" };
                          using (var connection = factory.CreateConnection())
                          {
                              using (var channel = connection.CreateModel())
                              {
                                  IDictionary <String , Object> args = new Dictionary<String,Object>() ;
                                  args.Add(" x-max-priority ", 10);
                                  channel.QueueDeclare("task_queue1", true, false, true, args);
                  
                                  for (int i = 1 ; i<=10; i++ )
                                  {
                                      var message = "Message";
                                      var body = Encoding.UTF8.GetBytes(message + " " + i);
                                      var properties = channel.CreateBasicProperties();
                                      properties.SetPersistent(true);
                                      properties.Priority = Convert.ToByte(i);
                                      channel.BasicPublish("", "task_queue1", properties, body);
                                  }
                              }
                          }
                      }
                  }
                  

                  消费者:

                  using System;
                  using RabbitMQ.Client;
                  using RabbitMQ.Client.Events;
                  using System.Text;
                  using System.Threading;
                  using System.Collections.Generic;
                  
                  namespace Consumer
                  { 
                      class Worker
                      {
                          public static void Main()
                          {
                              var factory = new ConnectionFactory() { HostName = "localhost" };
                              using (var connection = factory.CreateConnection())
                              {
                                  using (var channel = connection.CreateModel())
                                  {
                                      IDictionary<String, Object> args = new Dictionary<String, Object>();                      
                                      channel.BasicQos(0, 1, false);
                                      var consumer = new QueueingBasicConsumer(channel);
                                      IDictionary<string, object> consumerArgs = new Dictionary<string, object>();
                                      channel.BasicConsume( "task_queue1", false, "", args, consumer);
                                      Console.WriteLine(" [*] Waiting for messages. " +
                                                        "To exit press CTRL+C");
                                      while (true)
                                      {
                                          var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
                                          var body = ea.Body;
                                          var message = Encoding.UTF8.GetString(body);
                                          Console.WriteLine(" [x] Received {0}", message);
                                          channel.BasicAck(ea.DeliveryTag, false);
                                      }
                                  }
                              }
                          }
                      }
                  }
                  

                  实际输出:

                  [*] Waiting for messages. To exit press CTRL+C
                  [x] Received Message 1
                  [x] Received Message 2
                  [x] Received Message 3
                  [x] Received Message 4
                  [x] Received Message 5
                  [x] Received Message 6
                  [x] Received Message 7
                  [x] Received Message 8
                  [x] Received Message 9
                  [x] Received Message 10
                  

                  预期输出:

                  [*] Waiting for messages. To exit press CTRL+C
                  [x] Received Message 10
                  [x] Received Message 9
                  [x] Received Message 8
                  [x] Received Message 7
                  [x] Received Message 6
                  [x] Received Message 5
                  [x] Received Message 4
                  [x] Received Message 3
                  [x] Received Message 2
                  [x] Received Message 1
                  

                  更新 #1.我在 Java 中找到了一个示例 这里.然而,它是 Rabbit 3.4.x.x.已合并到 3.5 中的插件.我能看到的唯一区别是它们将优先级表示为一个 int 而我的是一个字节.但我觉得这是一个红鲱鱼.我在这里有点不知所措.

                  UPDATE #1. I found an example in Java here. However it's the Rabbit 3.4.x.x. addin that was incorporated into 3.5. The only difference I can see is that they express the priority as an int and mine is a byte. But I feel like that's a red herring. I'm at a bit of a loss here.

                  推荐答案

                  好吧,我解决了.这是一个愚蠢的错误.我写道:

                  Well I solved it. It was a dumb mistake. I wrote:

                  args.Add(" x-max-priority ", 10);
                  

                  应该是的

                  args.Add("x-max-priority", 10);
                  

                  我会留下这个,以便其他人可以在 C# 中获得 Rabbitmq 3.5 的优先级队列的工作示例.

                  I'll leave this up so other people can have a working example of Rabbitmq 3.5's Priority Queues in C#.

                  这篇关于RabbitMQ 3.5 和消息优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将异构 JSON 数组反序列化为协变列表&lt;& 下一篇:RabbitMQ + C# + SSL

                  相关文章

                  最新文章

                  <tfoot id='tS1ih'></tfoot>

                2. <legend id='tS1ih'><style id='tS1ih'><dir id='tS1ih'><q id='tS1ih'></q></dir></style></legend>

                  <small id='tS1ih'></small><noframes id='tS1ih'>

                    <i id='tS1ih'><tr id='tS1ih'><dt id='tS1ih'><q id='tS1ih'><span id='tS1ih'><b id='tS1ih'><form id='tS1ih'><ins id='tS1ih'></ins><ul id='tS1ih'></ul><sub id='tS1ih'></sub></form><legend id='tS1ih'></legend><bdo id='tS1ih'><pre id='tS1ih'><center id='tS1ih'></center></pre></bdo></b><th id='tS1ih'></th></span></q></dt></tr></i><div id='tS1ih'><tfoot id='tS1ih'></tfoot><dl id='tS1ih'><fieldset id='tS1ih'></fieldset></dl></div>
                    • <bdo id='tS1ih'></bdo><ul id='tS1ih'></ul>