azure-service-fabric - Service Fabric 多个通信监听器

标签 azure-service-fabric

基本思想 - 我有一个无状态服务,它通过 http 实现 Owin 通信监听器,以服务基于 WebApi 的公共(public)客户端。我想添加第二个监听器,它将使用内置的 ServiceRemotingListener() 通过 Rpc 在集群内接收请求。原因是我不希望这个监听器是公共(public)的,因为它为无状态服务实现了一个非公共(public)的管理接口(interface)。这是设置...:

        protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        return new[]
        {
            new ServiceInstanceListener(initParams => new OwinCommunicationListener("MyWebService", new Startup(_options, this), initParams),"MyServiceHttp"),
            new ServiceInstanceListener(initParams => new ServiceRemotingListener<Interfaces.IConfig>(initParams, this),"MyServiceRpc")           
        };
    }

当我添加第二个监听器时,启动应用程序时出现异常...

                 this.serverHandle = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Configuration(appBuilder));

Exception thrown: 'System.Net.Sockets.SocketException' in System.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.ServiceModel.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.ServiceModel.dll Exception thrown: 'System.ServiceModel.CommunicationException' in System.ServiceModel.Internals.dll --multiple repeats--- Exception thrown: 'System.ServiceModel.CommunicationException' in System.Fabric.dll

(不确定如何获取异常详细信息。我的“try {}”环绕 没有捕获异常。)

一旦处于这种状态,我会在服务尝试自动重启时收到后续异常 - 这些错误与端口共享有关。

我可以做些什么来让 WebApi 通信监听器与 ServiceRemotingListener 一起工作?我假设在这一点上,ServiceRemotingListener 也在使用 http 并且它们不能很好地协同工作。

最佳答案

好的,结果证明解决方案很简单,但并不明显。即使 TCP/RPC 和 HTTP 不能一起使用,文档似乎也鼓励端口共享方法。

基本上,我在服务 list 中添加了第二个端点,尽管文档说每个服务只能监听一个端口。

我保留了 ServiceRemotingListener 注册的默认/第一个端点,并添加了第二个专门监听端口 8083 的端点。

<Endpoint Name="ServiceEndpoint" Protocol="http" Type ="Input"/>
<Endpoint Name="ServiceEndpoint2" Protocol="http" Port="8083" Type ="Input"/>

然后在 IOwinCommunicationsListener 中,我指定了第二个端点,它选择了备用端口号(我假设 ServiceInstanceListener 将使用默认/第一个端点)。

var codePackageActivationContext = this.serviceInitializationParameters.CodePackageActivationContext;
var port = codePackageActivationContext.GetEndpoint("ServiceEndpoint2").Port;

CreateServiceInstanceListeners 没有任何额外的配置。如上,我想知道是否可以使用ServiceRemoteListenerSettings来强制ServiceRemotinglistener使用替代端口而不是上面的IOwinCommunicationsListener)

        return new[]
        {
            new ServiceInstanceListener(initParams => new ServiceRemotingListener<Interfaces.IConfig>(initParams, this),"MyRpc"),
            new ServiceInstanceListener(initParams => new OwinCommunicationListener("ShopifyWebService", new Startup(_options, this), initParams),"MyOwin")
               };

希望这有助于为其他人节省大量时间。

关于azure-service-fabric - Service Fabric 多个通信监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34836150/

相关文章:

azure-service-fabric - 可以在 Azure Service Fabric 中创建各种开发和测试环境

azure - Service Fabric 负载平衡超时

c# - 服务结构: Reliable Services pipeline with partitions load balancing

ssl - ServiceFabric 本地集群 SSL

azure-service-fabric - Azure Service Fabric - 当消息到达 Azure 存储队列时触发服务/Actor

c# - 为本地集群安装证书

Azure Fabric SDK webapi 无法访问

c# - Service Fabric 无法加载程序集 c#

c# - 访问 Azure Service Fabric 有状态服务状态

azure - 从 Internet 访问 Service Fabric