Pub/Sub 和 Service Fabric 中的 OWIN

Pub/Sub and OWIN in Service Fabric

我正在 Service Fabric 中开发一个应用程序,它使用自托管 SignalR(通过 OWIN)向客户端发送实时数据。

在我的微服务中,我有一个无状态服务 (S1),它从 Pub/Sub 代理接收数据并将所述数据发送到通过 SignalR 连接的客户端。我使用 this library 在 Service Fabric 中实现 Pub/Sub。我知道我可以使用服务总线、RedisCache 等作为 Pub/Sub 提供程序,但我的团队已决定尽量避免使用 Service Fabric 之外的任何选项。

this example 之后,我成功地将 S1 设置为订阅者。但是,一旦我添加了自托管 SignalR 服务器的代码,S1 就会停止从 Pub/Sub.

接收数据

我已将错误缩小到以下代码块:

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

如图所示,SignalR 服务器已禁用,Pub/Sub 工作正常。取消注释行启用 SignalR 服务器,Pub/Sub 停止工作。

谁能帮我理解为什么会这样?欢迎任何想法或建议。

请先让出 SubscriberCommunicationListener。该框架尚未向目标提供通信侦听器名称,因此使用第一个。