【问题标题】:Service Fabric Multiple Communication ListenersService Fabric 多个通信侦听器
【发布时间】:2016-04-22 12:39:33
【问题描述】:

基本思想 - 我有一个无状态服务,它通过 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")           
        };
    }

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

                 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”

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

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

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

【问题讨论】:

  • 我使用的端口好像被防火墙阻止了。我得到了同样的异常,但现在我也得到了一个具有相同错误的 CommunicationException,但它将端口标识为 0.0.0.0:8080。 " 侦听 IP Endpoint=0.0.0.0:8080 时发生 TCP 错误(10013:尝试以访问权限禁止的方式访问套接字)。"
  • ServiceRemotingListener 不使用 HTTP。如果没有 OwinCommunicationListener,您可以让 ServiceRemotingLIsener 自行工作吗?
  • 我会试一试,明天再报告。谢谢!
  • 当我自己设置 ServiceRemotingListener 时,节点报告 {"Endpoints":{"MyRpc":"net.tcp:\/\/localhost:8083\/2c44446c-4c4e-479a -ac48-13c5b664b8c6\/0b91d2a3-80c3-4c30-b9b4-490672a8c077-130979017853872413"}}。调查为什么决定使用 tcp....
  • ..当我使用监听地址“http://+:8083/bc35bdfc-c488-473e-aaa2-5bdc6b763b9f/130979290464827805/99d163c8-e462-4a8f-8bfa-”添加IOwinCommunicationListener 821d9308790e”,我再次收到“试图以访问权限禁止的方式访问套接字”错误。

标签: azure-service-fabric


【解决方案1】:

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

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

我保留了 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")
               };

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

【讨论】:

  • 如果我有多个输入端点,我将如何从浏览器调用这些端点?
  • 不确定我是否完全理解您的问题,但这是一个尝试。最简单的第一个 - 我已经设置为端口 8083 的第二个侦听器,因此我可以通过 hostname:8083/<yourpath> 访问。对于第一个侦听器,您可以在服务内通过服务实例侦听器查询 ServiceFabric 分配的端口,然后发布或写入该值。或者,从服务结构客户端,您可以通过服务分区客户端使用名称服务来查询服务端点。查看 Wordcount 演示并查看无状态服务,了解它如何查找有状态服务端点。
  • 此外,首先指定哪个端点以及首先创建哪个侦听器似乎很重要。
  • 您能否根据 appmanifest 中的设置覆盖您使用的端点?例如,如果您只想通过更改 1 个配置设置将整个应用程序从 http 切换到 https?
猜你喜欢
  • 2016-01-19
  • 1970-01-01
  • 2021-02-09
  • 2016-11-09
  • 2017-11-02
  • 2016-07-13
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多