服务结构多个通信侦听器 [英] Service Fabric Multiple Communication Listeners

查看:58
本文介绍了服务结构多个通信侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Basic Idea - I have a stateless service that implements an Owin communication Listener over http to service WebApi based public clients. I want to add a second listener that will receive requests within the cluster over Rpc using the built in ServiceRemotingListener(). The reason is that I don't want this listener to be public as it implements a non-public management interface for the stateless service. Here is the setup...:

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

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

When I add the second listener, I get an exception starting the app...

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

引发的异常: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'

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

(不确定如何获取异常详细信息.我的尝试{}"周围 没有捕获到异常.)

(not sure how to get the exception details. My "try {} " surrounding did not trap an exception.)

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

Once in this state, I get subsequent exceptions as the service attempts to auto-restart - the errors are about port sharing.

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

Anything I can do to make WebApi communication listeners work alongside ServiceRemotingListener? I am assuming at this point that under the hood, ServiceRemotingListener is using http as well and they don't play nicely together.

推荐答案

好的,结果证明是直接的,但并不明显.即使TCP/RPC和HTTP不能一起使用,文档似乎也鼓励端口共享方法.

ok, the solution turned out to be straight forward but not obvious. The docs seem to encourage port sharing approach even though the TCP/RPC and HTTP don't play together.

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

Basically, I added a second endpoint to the service manifest even though the docs say that each service can only listen on one port.

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

I left the default / first endpoint for the ServiceRemotingListener to register and added a second that listened specifically to port 8083.

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

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

Then in the IOwinCommunicationsListener, I specified the second endpoint which picked up the alternative port number (I assumed the ServiceInstanceListener would use the default/first end point).

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

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

The CreateServiceInstanceListeners were left without any extra config. As above, I wonder if I could use the ServiceRemoteListenerSettings to force the ServiceRemotinglistener to use the alternative port instead of the IOwinCommunicationsListener above)

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

希望这可以节省很多时间.

Hope this helps save someone else a lot of time.

这篇关于服务结构多个通信侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆