仅第一次使用MessageReceiver
使用Azure函数从主题获取消息,之后下次执行函数时,尽管我有消息进入服务总线主题
,但变量仍然为空消息
.
使用下面的代码从服务总线主题获取消息,原因是什么?
string serviceBusConnectionString = Environment.GetEnvironmentVariable("ConnectionString");
var messageReceiver = new MessageReceiver(serviceBusConnectionString, Environment.GetEnvironmentVariable("topicName/subscriptions/subscriptionName"), ReceiveMode.PeekLock, null, 500);
var messages = await messageReceiver.ReceiveAsync(500, TimeSpan.FromSeconds(1));
i can't understand this - after every 15 minutes when LA call FA then FA should able to read new available messages but it is coming null
与锁定持续时间有什么关系吗?
最佳答案
var messages = await messageReceiver.ReceiveAsync(500, TimeSpan.FromSeconds(1));
将等待,直到收到一条或多条消息,然后返回。稍后传入的任何消息都不会被读取。如果你想这样做(我怀疑这在 Azure 函数中是否是一个好主意),请将其放入循环中:
while(/* some condition */)
{
messages = await messageReceiver.ReceiveAsync(500, TimeSpan.FromSeconds(1));
// do something with the received messages
}
关于c# - 仅在第一次使用 Azure Function HttpTrigger 从主题获取消息时使用 MessageReceiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59421738/