Search code examples
azuresignalrowinpublish-subscribeazure-service-fabric

Pub/Sub and OWIN in Service Fabric


I'm developing a app in Service Fabric which uses self-hosted SignalR (via OWIN) to send real-time data to a client.

Among my microservices I have one Stateless Service (S1) that receives data from a Pub/Sub broker and sends said data to clients connected via SignalR. I'm use this library to implement Pub/Sub in Service Fabric. I'm aware I could use Service Bus, RedisCache, etc as Pub/Sub providers, but my team has decided to try to avoid any options outside Service Fabric.

Following this example I managed to successfuly setup S1 as a subscriber. However as soon as I add the code for self-hosted SignalR server, S1 stops receiving data from Pub/Sub.

I've narrowed the error down to the following block of code:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
    // yield return new ServiceInstanceListener(serviceContext => new OwinCommunicationListener(Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, "HttpEndpoint"));
    yield return new ServiceInstanceListener(p => new SubscriberCommunicationListener(this, p), "StatelessSubscriberCommunicationListener");
    yield return new ServiceInstanceListener(context => new FabricTransportServiceRemotingListener(context, this, new FabricTransportRemotingListenerSettings() { EndpointResourceName = "PubSubEndpoint" }), "StatelessFabricTransportServiceRemotingListener");
}

As presented, the SignalR server is disabled and the Pub/Sub works flawlessly. Uncommenting the line enables the SignalR server and the Pub/Sub stops working.

Can anyone help me understand why this happens? Any ideas or sugestions are welcome.


Solution

  • Please yield the SubscriberCommunicationListener first. The framework doesn't supply the communication listener name to target yet, so the first one is used.