首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Azure service Bus的.NET SDK在c#中读取服务总线主题及其订阅中的死信计数?

如何使用Azure service Bus的.NET SDK在c#中读取服务总线主题及其订阅中的死信计数?
EN

Stack Overflow用户
提问于 2021-09-16 04:39:11
回答 2查看 391关注 0票数 1

Azure Monitor为服务总线提供了许多指标,例如“传入、传出、活动的”消息Service bus Matrics,为您提供了总的消息计数,当我试图查看该指标“DeadletteredMessages”的详细信息时,我可以通过“EntityName”来获得计数,它既可以是一个队列,也可以是一个主题,而不是订阅级别的指标。

当我从主题及其订阅中获取所有死信和其他消息计数时,我面临着挑战。我花了差不多4-5个小时来解决上面的问题。

我希望下面的答案能对监控服务总线有所帮助

EN

回答 2

Stack Overflow用户

发布于 2021-09-16 04:39:11

代码语言:javascript
复制
Here is the sample code for the same.

[FunctionName("ServiceBusMonitor")]
        public async Task Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
        {
            try
            {
                var client = new ServiceBusAdministrationClient(_configuration.GetValue<string>("ServiceBusConnectionString"));
                var topics = client.GetTopicsAsync()?.GetAsyncEnumerator();
                while (await topics.MoveNextAsync())
                {
                    TopicProperties topicProperties = topics.Current;
                    var subscriptions = client.GetSubscriptionsAsync(topicProperties.Name)?.GetAsyncEnumerator();
                    log.LogInformation($"{topicProperties.Name}");

                    var subscriptionRuntimePropertiesAsync = client.GetSubscriptionsRuntimePropertiesAsync(topicProperties.Name)?.GetAsyncEnumerator();
                    while (await subscriptionRuntimePropertiesAsync.MoveNextAsync())
                    {
                        var subscriptionRuntimeProperties = subscriptionRuntimePropertiesAsync.Current;
                        Console.WriteLine($"Topic Name {subscriptionRuntimeProperties.TopicName}, Subscription Name {subscriptionRuntimeProperties.SubscriptionName}");
                        Console.WriteLine($"DeadLetterMessageCount : {subscriptionRuntimeProperties.DeadLetterMessageCount} ActiveMessageCount : {subscriptionRuntimeProperties.ActiveMessageCount} TotalMessageCount : {subscriptionRuntimeProperties.TotalMessageCount} " );
//You can log subscriptionRuntimeProperties in Application insight and use the for the monitor
                    }
                    Console.WriteLine("-----------");
                }

                log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
            }
            catch (Exception ex)
            {
                log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now} {ex.Message}");

            }
        }
票数 2
EN

Stack Overflow用户

发布于 2021-09-16 07:17:49

只说监视服务总线,有一个很棒的工具叫做Service Bus Explorer

服务总线资源管理器允许用户有效地管理消息传递实体。该工具提供了一些高级功能,如导入/导出功能以及测试主题、队列、订阅、中继服务、通知中心和事件中心的能力。

当您选择特定队列或主题时,此工具的某些功能也可用(在预览中) via the Azure Portal

现在可以预览Azure门户上的服务总线资源管理器工具。

与大多数其他PaaS产品一样,Azure Service Bus有两组可以对其执行的操作:

对Service Bus名称空间、队列、主题、订阅和筛选器执行CRUD (创建、读取、更新和删除)等管理操作。发送、接收和查看队列、主题和订阅等数据操作。

这两种方法都可以让您手动跟踪主题和队列。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69202419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档