【发布时间】:2018-10-30 16:39:27
【问题描述】:
有没有办法使用Microsoft.Azure.ServiceBus 包来等待当前线程接收来自队列的消息?
这可能更多是我的理解和希望以不打算使用的方式使用该技术的问题,但我想做的是结合来自the following Microsoft example 的发送和接收示例,以便您可以将消息发送到各种队列,并能够监听和处理“回复”(只是您在队列中收听的消息)并在接收完消息后关闭连接。
这里有一些伪代码:
// send message(s) that will be consumed by other processes / applications, and by doing so later on we will expect some messages back
await SendMessagesAsync(numberOfMessages);
var receivedMessages = 0;
while (receivedMessages < numberOfMessages)
{
// there is no "ReceiveAsync" method, this is what I would be looking for
Message message = await queueClient.ReceiveAsync(TimeSpan.FromSeconds(30));
receivedMessages++;
// do something with the message here
}
await queueClient.CloseAsync();
这可能还是我“做错了”?
【问题讨论】:
-
ReceiveAsync 方法在 nuget.org/packages/WindowsAzure.ServiceBus/4.1.9 中可用,但在 nuget.org/packages/Microsoft.Azure.ServiceBus 中不可用。所以这里要么你可以使用第一个包,要么你可以写一个逻辑让
Recieve成为阻塞。
标签: c# azure azureservicebus azure-servicebus-queues