是否可以将 Azure 服务总线主题中包含的所有消息提取到应用程序中?
Is it possible to pull all messages contained in an Azure Servicebus Topic into an app?
我看到从主题中提取消息的唯一方法是 SubscriptionClient.OnMessage(),它似乎只在主题收到新消息时触发。
队列具有用于此目的的 QueueClient.Receive() 方法,但主题似乎没有此功能。
我是不是漏掉了什么?
看起来 SubscriptionClient.OnMessage()
实际上确实遍历了有关该主题的所有现有消息。
无法从主题接收消息,只能发送到。主题与订阅结合使用以接收消息。
队列和subscriptions support OnMessage API. This, though, won't give you all the messages, but instead will give one message at a time X the concurrency level you'll set with OnMessageOptions
。
另一种方法是接收批次(请参阅 ReceiveBatchAsync(Int32, TimeSpan)
)。如果需要,这将允许您处理多条消息。
首先,正如 Sean Feldman 所说,不会直接从主题中收到消息。此外,如果您想接收和处理所有消息,您可以使用默认(MatchAll)过滤器创建订阅,它将发布到主题的所有消息放入订阅的虚拟队列中,然后您可以接收和处理来自您应用程序中该订阅的消息。 This article描述了如何使用Service Bus主题和订阅,并举例说明,请参考。
另外,如果有必要,请记得检查和处理死信消息。
也许你需要MessageReceiver
var message = await messageReceiver.ReceiveAsync();
await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);
我看到从主题中提取消息的唯一方法是 SubscriptionClient.OnMessage(),它似乎只在主题收到新消息时触发。
队列具有用于此目的的 QueueClient.Receive() 方法,但主题似乎没有此功能。
我是不是漏掉了什么?
看起来 SubscriptionClient.OnMessage()
实际上确实遍历了有关该主题的所有现有消息。
无法从主题接收消息,只能发送到。主题与订阅结合使用以接收消息。
队列和subscriptions support OnMessage API. This, though, won't give you all the messages, but instead will give one message at a time X the concurrency level you'll set with OnMessageOptions
。
另一种方法是接收批次(请参阅 ReceiveBatchAsync(Int32, TimeSpan)
)。如果需要,这将允许您处理多条消息。
首先,正如 Sean Feldman 所说,不会直接从主题中收到消息。此外,如果您想接收和处理所有消息,您可以使用默认(MatchAll)过滤器创建订阅,它将发布到主题的所有消息放入订阅的虚拟队列中,然后您可以接收和处理来自您应用程序中该订阅的消息。 This article描述了如何使用Service Bus主题和订阅,并举例说明,请参考。
另外,如果有必要,请记得检查和处理死信消息。
也许你需要MessageReceiver
var message = await messageReceiver.ReceiveAsync();
await messageReceiver.CompleteAsync(message.SystemProperties.LockToken);