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

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

        <bdo id='Amgax'></bdo><ul id='Amgax'></ul>
      1. RabbitMQ C# 验证消息已发送

        时间:2023-08-24
          <bdo id='ooVMa'></bdo><ul id='ooVMa'></ul>

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

              <legend id='ooVMa'><style id='ooVMa'><dir id='ooVMa'><q id='ooVMa'></q></dir></style></legend>

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

                  <tfoot id='ooVMa'></tfoot>
                1. 本文介绍了RabbitMQ C# 验证消息已发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是 RabbitMQ 的新手,正在尝试写入队列并验证消息是否已发送.如果它失败了,我需要知道它.我做了一个假队列来观察它失败,但无论我看到什么都没有异常,当我在寻找一个确认时,我总是得到一个.我从没见过 BasicNack.

                  I'm new to RabbitMQ and trying to write to a Queue and verify the message was sent. If it fails I need to know about it. I made a fake queue to watch it fail but no matter what I see no execptions and when I am looking for a ack I always get one. I never see the BasicNack.

                  我什至不确定我是否是 BasicAcks 是要走的路.

                  I'm not even sure i'm the BasicAcks is the way to go.

                      private void button1_Click(object sender, EventArgs e)
                      {
                          var factory = new ConnectionFactory() { HostName = "localhost" };
                          using (var connection = factory.CreateConnection())
                          {
                              using (var channel = connection.CreateModel())
                              {
                                  channel.QueueDeclare("task_queue", true, false, false, null);
                  
                                  var message = ("Helllo world");
                                  var body = Encoding.UTF8.GetBytes(message);
                                  channel.ConfirmSelect();
                  
                                  var properties = channel.CreateBasicProperties();
                                  properties.SetPersistent(true);
                                  properties.DeliveryMode = 2;
                                  channel.BasicAcks += channel_BasicAcks;
                                  channel.BasicNacks += channel_BasicNacks;
                                  //fake queue should be task_queue
                                  channel.BasicPublish("", "task_2queue", true, properties, body);
                  
                                  channel.WaitForConfirmsOrDie();
                  
                                  Console.WriteLine(" [x] Sent {0}", message);
                              }
                          }
                      }
                  
                      void channel_BasicNacks(IModel model, BasicNackEventArgs args)
                      {
                  
                      }
                  
                      void channel_BasicAcks(IModel model, BasicAckEventArgs args)
                      {
                  
                      }
                  

                  推荐答案

                  对于那些寻找 C# 答案的人 - 这就是您所需要的.

                  For those looking for a C# answer - here is what you need.

                  https://rianjs.net/2013/12/publisher-confirms-with-rabbitmq-and-c-sharp

                  类似这样的:(BasicAcks 附加了一个事件处理程序 - 还有 BasicNacks)

                  Something like this: (BasicAcks attaches an event handler - there is also BasicNacks)

                  using (var connection = FACTORY.CreateConnection())
                  {
                      var channel = connection.CreateModel();
                      channel.ExchangeDeclare(QUEUE_NAME, ExchangeType.Fanout, true);
                      channel.QueueDeclare(QUEUE_NAME, true, false, false, null);
                      channel.QueueBind(QUEUE_NAME, QUEUE_NAME, String.Empty, new Dictionary<string, object>());
                       channel.BasicAcks += (sender, eventArgs) =>
                                  {
                                      //implement ack handle
                                  };
                      channel.ConfirmSelect();
                  
                      for (var i = 1; i <= numberOfMessages; i++)
                      {
                          var messageProperties = channel.CreateBasicProperties();
                          messageProperties.SetPersistent(true);
                  
                          var message = String.Format("{0}	hello world", i);
                          var payload = Encoding.Unicode.GetBytes(message);
                          Console.WriteLine("Sending message: " + message);
                          channel.BasicPublish(QUEUE_NAME, QUEUE_NAME, messageProperties, payload);
                          channel.WaitForConfirmsOrDie();
                      }
                  }
                  

                  这篇关于RabbitMQ C# 验证消息已发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:获取 MassTransit 消息重试次数 下一篇:从静态工厂类访问 ASP.NET Core DI 容器

                  相关文章

                  最新文章

                  1. <small id='ImP3C'></small><noframes id='ImP3C'>

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

                    <tfoot id='ImP3C'></tfoot>
                      <bdo id='ImP3C'></bdo><ul id='ImP3C'></ul>