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

      2. <legend id='e8HTI'><style id='e8HTI'><dir id='e8HTI'><q id='e8HTI'></q></dir></style></legend>
      3. <small id='e8HTI'></small><noframes id='e8HTI'>

      4. RabbitMQ 异步支持

        时间:2023-08-26
        <i id='4j6Ro'><tr id='4j6Ro'><dt id='4j6Ro'><q id='4j6Ro'><span id='4j6Ro'><b id='4j6Ro'><form id='4j6Ro'><ins id='4j6Ro'></ins><ul id='4j6Ro'></ul><sub id='4j6Ro'></sub></form><legend id='4j6Ro'></legend><bdo id='4j6Ro'><pre id='4j6Ro'><center id='4j6Ro'></center></pre></bdo></b><th id='4j6Ro'></th></span></q></dt></tr></i><div id='4j6Ro'><tfoot id='4j6Ro'></tfoot><dl id='4j6Ro'><fieldset id='4j6Ro'></fieldset></dl></div>

          <bdo id='4j6Ro'></bdo><ul id='4j6Ro'></ul>
            <tbody id='4j6Ro'></tbody>

        • <legend id='4j6Ro'><style id='4j6Ro'><dir id='4j6Ro'><q id='4j6Ro'></q></dir></style></legend>
        • <small id='4j6Ro'></small><noframes id='4j6Ro'>

                  <tfoot id='4j6Ro'></tfoot>
                1. 本文介绍了RabbitMQ 异步支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  RabbitMQ .NET 客户端是否有任何类型的异步支持?我希望能够异步连接和使用消息,但到目前为止还没有找到方法.

                  Does the RabbitMQ .NET client have any sort of asynchronous support? I'd like to be able to connect and consume messages asynchronously, but haven't found a way to do either so far.

                  (对于消费消息,我可以使用 EventingBasicConsumer,但这不是一个完整的解决方案.)

                  只是为了提供一些上下文,这是我目前如何使用 RabbitMQ 的一个示例(代码取自我的博客):

                  Just to give some context, this is an example of how I'm working with RabbitMQ at the moment (code taken from my blog):

                  var factory = new ConnectionFactory() { HostName = "localhost" };
                  
                  using (var connection = factory.CreateConnection())
                  {
                      using (var channel = connection.CreateModel())
                      {
                          channel.QueueDeclare("testqueue", true, false, false, null);
                  
                          var consumer = new EventingBasicConsumer(channel);
                          consumer.Received += Consumer_Received;
                          channel.BasicConsume("testqueue", true, consumer);
                  
                          Console.ReadLine();
                      }
                  }
                  

                  推荐答案

                  Rabbit 支持使用 AsyncEventingBasicConsumer 类分派到异步消息处理程序.它的工作方式类似于 EventingBasicConsumer,但允许您注册一个返回 Task 的回调.回调被调度到,返回的 Task 由 RabbitMQ 客户端等待.

                  Rabbit supports dispatching to asynchronous message handlers using the AsyncEventingBasicConsumer class. It works similarly to EventingBasicConsumer, but allows you to register a callback which returns a Task. The callback is dispatched to and the returned Task is awaited by the RabbitMQ client.

                  var factory = new ConnectionFactory
                  {
                      HostName = "localhost",
                      DispatchConsumersAsync = true
                  };
                  
                  using(var connection = cf.CreateConnection())
                  {
                      using(var channel = conn.CreateModel())
                      {
                          channel.QueueDeclare("testqueue", true, false, false, null);
                  
                          var consumer = new AsyncEventingBasicConsumer(model);
                  
                          consumer.Received += async (o, a) =>
                          {
                              Console.WriteLine("Message Get" + a.DeliveryTag);
                              await Task.Yield();
                          };
                      }
                  
                      Console.ReadLine();
                  }
                  

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

                  上一篇:如何在 RabbitMQ 中设置重试次数? 下一篇:指定公共交通中的发布超时

                  相关文章

                  最新文章

                  <small id='9UmXm'></small><noframes id='9UmXm'>

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