azure - ReadEventsAsync EventHub 不会停止

标签 azure azure-eventhub azure-eventgrid azure-eventhub-client

我正在 Azure 事件中心存储一些应用程序生成的消息,这些消息是由 Web 应用程序生成的,我想在 Rest API 调用中从 Azure 事件中心检索这些消息,以在 Web 应用程序中显示这些消息。

Issue

当我尝试使用以下代码从 Azure 事件中心读取消息时

var messages = new List<MessagingModel>();

            string consumerGroup = EventHubConsumerClient.DefaultConsumerGroupName;

            await using (var consumerClient = new EventHubConsumerClient(consumerGroup, eventHubConnectionString, eventHubName))
            {
                await foreach (var partitionEvent in consumerClient.ReadEventsAsync())
                {
                    string json = Encoding.UTF8.GetString(partitionEvent.Data.Body.ToArray());
                    var message = JsonConvert.DeserializeObject<MessagingModel>(json);
                    Console.WriteLine(json);
                }

                await consumerClient.CloseAsync();
            }

            return messages;

控件永远不会出来,这不是我们想要的,我还观察到,当新消息发送到事件中心时,控件返回处理该消息,然后等待下一条消息出现.

我只想阅读消息列表。

最佳答案

关于azure - ReadEventsAsync EventHub 不会停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76133010/

相关文章:

Azure 部署失败

c# - Azure Functions 的事件中心输入绑定(bind)

azure - 如何在网络上显示 blob 中的图像

azure - Kusto 如果数组包含数组则不返回结果

azure - 使用 AZURE 事件中心的 Kafka 格式的 SSL 证书用法

azure - 如何使用 Azure Functions 将 Azure 资源的流式诊断日志从事件中心推送到 Log Analytics 工作区?

Azure 事件网格高级筛选为 Not Null 运算符

azure - 逻辑应用订阅事件网格域内的主题

azure - Azure EventGrid 主题中的多种事件类型

azure - JWT验证: Caching JWKS derived from cached discovery document via Azure API Management