订阅Service Fabric群集级别的事件 [英] Subscribing to Service Fabric cluster level events

查看:110
本文介绍了订阅Service Fabric群集级别的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个服务,该服务将更新在我的服务结构群集中运行的应用程序的服务端点的外部列表. (基本上,我需要在本地F5负载均衡器中复制Azure负载均衡器.)

I am trying to create a service that will update an external list of Service Endpoints for applications running in my service fabric cluster. (Basically I need to replicate the Azure Load Balancer in my on premises F5 Load Balancer.)

在上个月的服务结构Q& A中,团队向我指出了 RegisterServiceNotificationFilterAsync .

During last month's Service Fabric Q&A, the team pointed me at RegisterServiceNotificationFilterAsync.

我使用这种方法提供了无状态服务,并将其部署到了我的开发集群中.然后,我通过运行ASP.NET Core无状态服务模板来提供新服务.

I made a stateless service using this method, and deployed it to my development cluster. I then made a new service by running the ASP.NET Core Stateless service template.

我希望当我部署第二个服务时,断点会碰到我的第一个服务,表明已经添加了一个服务.但是没有断点.

I expected that when I deployed the second service, the break point would hit in my first service, indicating that a service had been added. But no breakpoint was hit.

我在互联网上发现这种事例的方式很少,所以我在这里问是希望其他人做到了这一点,并且可以告诉我我哪里出了问题.

I have found very little in the way of examples for this kind of thing on the internet, so I am asking here hopping that someone else has done this and can tell me where I went wrong.

这是我的服务的代码,试图捕获应用程序更改:

Here is the code for my service that is trying to catch the application changes:

protected override async Task RunAsync(CancellationToken cancellationToken)
{

    var fabricClient = new FabricClient();

    long? filterId = null;


    try
    {
        var filterDescription = new ServiceNotificationFilterDescription
        {
            Name = new Uri("fabric:")
        };
        fabricClient.ServiceManager.ServiceNotificationFilterMatched += ServiceManager_ServiceNotificationFilterMatched;
        filterId = await fabricClient.ServiceManager.RegisterServiceNotificationFilterAsync(filterDescription);


        long iterations = 0;

        while (true)
        {
            cancellationToken.ThrowIfCancellationRequested();

            ServiceEventSource.Current.ServiceMessage(this.Context, "Working-{0}", ++iterations);

            await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
        }
    }
    finally
    {
        if (filterId != null)
            await fabricClient.ServiceManager.UnregisterServiceNotificationFilterAsync(filterId.Value);
    }



}

private void ServiceManager_ServiceNotificationFilterMatched(object sender, EventArgs e)
{
    Debug.WriteLine("Change Occured");
}

如果您对如何进行操作有任何建议,我很乐意看到它们.

If you have any tips on how to get this going, I would love to see them.

推荐答案

您需要设置

You need to set the MatchNamePrefix to true, like this:

    var filterDescription = new ServiceNotificationFilterDescription
    {
        Name = new Uri("fabric:"),
        MatchNamePrefix = true
    };

否则它将仅匹配特定服务.在我的应用程序中,将此参数设置为true时,我可以捕获群集范围的事件.

otherwise it will only match specific services. In my application I can catch cluster wide events when this parameter is set to true.

这篇关于订阅Service Fabric群集级别的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆