Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscribing to Service Fabric cluster level events

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.)

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

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.

like image 525
Vaccano Avatar asked Jul 21 '17 21:07

Vaccano


People also ask

What is service cluster Fabric?

A Service Fabric cluster is a network-connected set of virtual or physical machines into which your microservices are deployed and managed. A machine or VM that is part of a cluster is called a cluster node. Clusters can scale to thousands of nodes.

How do I upgrade service Fabric cluster?

Get the list of Service Fabric versions that you can upgrade to. Start a cluster upgrade to an available version by using the Start-ServiceFabricClusterUpgrade Windows PowerShell command. If the cluster health policies aren't met, the upgrade is rolled back.

How many nodes can be maintained on a service Fabric cluster?

A single Service Fabric node type/scale set can not contain more than 100 nodes/VMs. To scale a cluster beyond 100 nodes, add additional node types.

Which types of microservices are supported with Azure service Fabric?

Service Fabric provides a sophisticated, lightweight runtime that supports stateless and stateful microservices.


1 Answers

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

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

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

like image 190
Peter Bons Avatar answered Nov 08 '22 15:11

Peter Bons