【问题标题】:Subscribing to Service Fabric cluster level events订阅 Service Fabric 群集级别事件
【发布时间】:2017-12-28 01:40:20
【问题描述】:

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

在上个月的 Service Fabric 问答中,团队将我指向 RegisterServiceNotificationFilterAsync

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

我预计当我部署第二个服务时,断点会在我的第一个服务中命中,表明已经添加了一个服务。但是没有命中断点。

我在互联网上找到的这种事情的例子很少,所以我在这里问一下,其他人已经这样做了,可以告诉我哪里出错了。

这是我的服务的代码,它试图捕捉应用程序的变化:

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");
}

如果您对如何实现这一点有任何建议,我很乐意看到它们。

【问题讨论】:

  • 与您的问题并不真正相关,但是.. Basically I need to replicate the Azure Load Balancer - 我没有关注您要在此处复制的功能是什么?据我所知,ALB 非常“愚蠢”并且不知道 SF?
  • 你可以试试Name = new Uri("fabric:/")
  • @LoekD - 因为这篇文章,我这样做了,微软员工说不要斜杠。 github.com/Azure/service-fabric-issues/issues/122 我确实尝试过,但我得到“无效的名称 URI”。
  • @Mardoxx - 在 6 月与 Service Fabric 团队的问答中,他们告诉我 Azure 负载均衡器会在节点重新启动时处理池更新。我想他们可能是错的。但无论哪种方式,我的 F5 都需要该功能。

标签: azure azure-service-fabric service-fabric-stateless


【解决方案1】:

您需要将MatchNamePrefix 设置为true,如下所示:

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

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

【讨论】:

    猜你喜欢
    • 2018-11-14
    • 2016-03-25
    • 2017-06-07
    • 2020-01-11
    • 2017-08-09
    • 2018-10-27
    • 2016-09-28
    • 2018-09-05
    • 2017-11-27
    相关资源
    最近更新 更多