如何获取NServiceBus的订阅者总数?

发布于 2024-10-09 10:47:12 字数 121 浏览 0 评论 0原文

我正在使用 NServiceBus,我需要知道有多少客户端订阅了特定的消息类型(更好的是订阅者的名称)。我正在谈论 pub\sub 场景。

是否可以在 NServiceBus 中获取此信息?

谢谢

I'm using NServiceBus and I need to know how many clients are subscribed to a specific message type (even better the names of the subscribers). I'm talking in a pub\sub scenario.

Is it possible to get this information in NServiceBus?

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

櫻之舞 2024-10-16 10:47:12

您可以直接将其从订阅存储中取出。对数据库的查询或队列上的 .GetAllMessages() 都会为您提供计数和订阅者地址。如果您想在代码中执行此操作,您可以为订阅消息编写一个处理程序并以这种方式对它们进行计数。

You can pull this right out of your subscription storage. Either a query to the database or a .GetAllMessages() on the queue will get you a count and the subscribers address. If you are looking to do this in code, you could write a handler for the subscription message and count them up that way.

女中豪杰 2024-10-16 10:47:12

我已经成功地使用了 ISubscriptionStorage。

public class SubscribersForMessageHandler :
             IHandleMessages<SubscribersForMessageRequest>
{
    public ISubscriptionStorage Storage { get; set; }
    public IBus Bus { get; set; }

    public void Handle(SubscribersForMessageRequest message)
    {
        Bus.Reply<SubscribersForMessageResponse>(m=>
        {
            m.SagaId = message.SagaId;
            m.MessageType = message.MessageType;
            m.SubscriberEndpoints = GetSubscribersForMessage(message.MessageType);
        });
    }

    private List<string> GetSubscribersForMessage(string type)
    {
        return Storage.GetSubscribersForMessage(
          new List<string> { type }).ToList();
    }
}

I have used ISubscriptionStorage with success.

public class SubscribersForMessageHandler :
             IHandleMessages<SubscribersForMessageRequest>
{
    public ISubscriptionStorage Storage { get; set; }
    public IBus Bus { get; set; }

    public void Handle(SubscribersForMessageRequest message)
    {
        Bus.Reply<SubscribersForMessageResponse>(m=>
        {
            m.SagaId = message.SagaId;
            m.MessageType = message.MessageType;
            m.SubscriberEndpoints = GetSubscribersForMessage(message.MessageType);
        });
    }

    private List<string> GetSubscribersForMessage(string type)
    {
        return Storage.GetSubscribersForMessage(
          new List<string> { type }).ToList();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文