gpt4 book ai didi

c# - Azure服务总线 "ReceiveAsync"

转载 作者:行者123 更新时间:2023-11-30 21:34:16 25 4
gpt4 key购买 nike

有没有办法使用 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 方法可在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com