Azure service fabric 服务结构多个通信侦听器

Azure service fabric 服务结构多个通信侦听器,azure-service-fabric,Azure Service Fabric,基本思想-我有一个无状态服务,它通过http实现Owin通信侦听器,为基于WebApi的公共客户端提供服务。我想添加第二个侦听器,该侦听器将使用内置的ServiceRemotingListener()通过Rpc在集群内接收请求。原因是我不希望此侦听器是公共的,因为它为无状态服务实现了非公共管理接口。这是设置…: protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceLi

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

        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")           
        };
    }
引发异常:System.dll中的“System.Net.Sockets.SocketException” 引发异常:System.ServiceModel.dll中的“System.ServiceModel.CommunicationException” 引发异常:System.ServiceModel.dll中的“System.ServiceModel.CommunicationException” 引发异常:System.ServiceModel.Internals.dll中的“System.ServiceModel.CommunicationException” --多次重复--- 引发异常:System.Fabric.dll中的“System.ServiceModel.CommunicationException”

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

在这种状态下,当服务尝试自动重新启动时,我会收到后续异常-错误与端口共享有关


我能做些什么使WebApi通信侦听器与ServiceRemotingListener一起工作?我现在假设ServiceRemotingListener也在使用http,它们不能很好地配合使用。

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

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

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

<Endpoint Name="ServiceEndpoint" Protocol="http" Type ="Input"/>
<Endpoint Name="ServiceEndpoint2" Protocol="http" Port="8083" Type ="Input"/>
CreateServiceInstanceListeners没有任何额外配置。如上所述,我想知道是否可以使用ServiceRemoteListenerSettings强制ServiceRemotinglistener使用替代端口而不是上面的IOwinCommunicationsListener)

returnnew[]
{
新ServiceInstanceListener(initParams=>new ServiceRemotingListener(initParams,this),“MyRpc”),
新的ServiceInstanceListener(initParams=>new OwInCommunicationsListener(“ShopifyWebService”、新启动(_选项,此)、initParams、“MyOwin”)
};

希望这能帮别人节省很多时间。

看起来我使用的端口被防火墙屏蔽了。我得到了相同的异常,但现在我也得到了一个带有相同错误的CommunicationException,但它将端口标识为0.0.0.0:8080。“在IP Endpoint=0.0.0.0:8080上侦听时发生TCP错误(10013:试图以其访问权限所禁止的方式访问套接字)。”ServiceRemotingListener不使用HTTP。你能让ServiceRemotingLIstener在没有OwIndocommunicationListener的情况下独立工作吗?我会试一试,明天再汇报。谢谢当我自己设置ServiceRemotingListener时,节点报告{“端点”:{“MyRpc”:“net.tcp:\/\/localhost:8083\/2c44446c-4c4e-479a-ac48-13c5b664b8c6\/0b91d2a3-80c3-4c30-b9b4-490672a8c077-130979017853872413”}。当我用一个监听地址“http://+:8083/bc35bdfc-c488-473e-aaa2-5bdc6b763b9f/130979290464827805/99d163c8-e462-4a8f-8bfa-821d9308790e”重新添加IOwinCommunicationListener时,我得到“试图以其访问权限所禁止的方式访问套接字”再次出错。如果我有多个输入端点,我将如何从浏览器中调用这些端点?我不确定我是否完全理解您的问题,但这里有一个尝试。首先是最简单的一个-我已经将第二个侦听器设置为端口8083,这样我就可以通过主机名8083/进行访问。对于第一个侦听器,您可以在服务内查询ServiceFabric通过服务实例侦听器分配的端口,然后发布或写入该值。或者,从ServiceFabric客户端,您可以通过ServicePartitionClient使用名称service来查询服务端点。请参阅Wordcount演示并查看无状态服务,了解它如何查找有状态的服务端点。此外,首先指定哪个端点以及首先创建哪个侦听器似乎很重要。是否可以根据appmanifest中的设置覆盖使用的端点?例如,如果您想通过更改1配置设置将整个应用程序从http切换到https?
<Endpoint Name="ServiceEndpoint" Protocol="http" Type ="Input"/>
<Endpoint Name="ServiceEndpoint2" Protocol="http" Port="8083" Type ="Input"/>
var codePackageActivationContext = this.serviceInitializationParameters.CodePackageActivationContext;
var port = codePackageActivationContext.GetEndpoint("ServiceEndpoint2").Port;
        return new[]
        {
            new ServiceInstanceListener(initParams => new ServiceRemotingListener<Interfaces.IConfig>(initParams, this),"MyRpc"),
            new ServiceInstanceListener(initParams => new OwinCommunicationListener("ShopifyWebService", new Startup(_options, this), initParams),"MyOwin")
               };