有没有一种使用Microsoft.Azure.ServiceBus
包的方法来等待您当前的线程从队列中接收消息?
就我的理解和以不打算使用该技术的方式使用该技术而言,这可能更多是一个问题,但是我想做的是结合the following Microsoft example的发送和接收示例,以便您可以发送消息( s)转到各种队列,并能够监听和处理“答复”(仅是您正在队列中正在监听的消息)并在完成接收消息后关闭连接。
一些伪代码在这里:
// 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
类提供了MessageReceiver
方法:
var messageReceiver = new MessageReceiver(SBConnString, QueueName, ReceiveMode.PeekLock);
Message message = await messageReceiver.ReceiveAsync();
在Get started sending and receiving messages from Service Bus queues using MessageSender and MessageReceiver上查看完整的示例。
关于c# - Azure服务总线 "ReceiveAsync",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50441796/