c# - 仅在第一次使用 Azure Function HttpTrigger 从主题获取消息时使用 MessageReceiver

标签 c# azure azure-functions azureservicebus

仅第一次使用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

enter image description here

与锁定持续时间有什么关系吗?

最佳答案

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/

相关文章:

C#6 : nameof() current property in getter/setter

python - 为什么 Azure ML 的得分概率响应大于 1?

Azure 逻辑应用程序用于更改我的函数应用程序的始终就绪实例的数量(弹性高级计划 EP1)

amazon-web-services - Azure Functions 是否有与 LambdaEntryPoint 等效的工具?

c# - TF命令行工具: Compare local sourcecode files with shelved TFS files

c# - 将 Google 日历解析为 DDay.iCal

azure - Visual Studio Code 中的 Terraform 解析错误

超过 20 天的 Azure 函数日志

c# - 如何在 net.core 3.1 上使用 DI 正确配置身份核心?

azure - 如何从 blob 存储触发 azure 函数中删除流参数