【问题标题】:Receiving messages from azure service bus从 azure 服务总线接收消息
【发布时间】:2015-05-18 18:40:12
【问题描述】:

可以使用这两种方法之一在 azure 服务总线中接收消息..

queueClient.BeginReceiveBatch 或 messageReceiver.ReceiveBatchAsync

这两种方法在速度方面或其他方面有什么区别。

谢谢

【问题讨论】:

  • 也许你可以在这里找到答案:stackoverflow.com/questions/3081079/…
  • @miracledev 感谢您的链接,但自过去 5 年以来发生了任何变化,例如 TPL 或其他任何东西..

标签: azure azureservicebus azure-servicebus-queues


【解决方案1】:

如果您不需要批量接收功能,我更喜欢在队列客户端的 OnMessage 事件上连接回调的方法。我们有一些相当高的吞吐量服务依赖于这种消息处理模式,没有任何问题(每天超过 100 万条消息)

我喜欢你最终得到更少、更简单的代码,并且可以轻松控制要并行处理的消息数量、接收模式(查看和锁定,与接收和删除)等选项

this documentation 中有一个示例:

string connectionString =
  CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
QueueClient Client =
  QueueClient.CreateFromConnectionString(connectionString, "TestQueue");

// Configure the callback options
OnMessageOptions options = new OnMessageOptions();
options.AutoComplete = false;
options.AutoRenewTimeout = TimeSpan.FromMinutes(1);

// Callback to handle received messages
Client.OnMessage((message) =>
{
    try
    {
        // Process message from queue
        Console.WriteLine("Body: " + message.GetBody<string>());
        Console.WriteLine("MessageID: " + message.MessageId);
        Console.WriteLine("Test Property: " +
        message.Properties["TestProperty"]);

        // Remove message from queue
        message.Complete();
    }
        catch (Exception)
    {
        // Indicates a problem, unlock message in queue
        message.Abandon();
    }
};

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多