代码之家  ›  专栏  ›  技术社区  ›  Ramon de Klein

无法在CreateServiceInstanceListeners中使用多个ServiceInstanceListener对象

  •  0
  • Ramon de Klein  · 技术社区  · 7 年前

    我已经创建了一个Service Fabric应用程序和 StatelessService.CreateServiceInstanceListeners ServiceInstanceListener CreateServiceInstanceListeners ,中止它们。。。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Ramon de Klein    7 年前

    返回的服务实例侦听器将添加到 ServiceListenerInstanceCollection

    ServiceInstanceListener构造函数具有以下实现:

    public ServiceInstanceListener(
       Func<StatelessServiceContext, ICommunicationListener> createCommunicationListener,
       string name = "")
    {
      this.CreateCommunicationListener = createCommunicationListener;
      this.Name = name;
    }
    

    默认名称是空字符串,因此如果不指定名称,则返回的枚举包含多个名为“”的侦听器,这将引发异常。默认实现中止已打开的侦听器并重新启动它们。

    解决办法很简单。创建时只需指定一个(唯一的)名称即可 ServiceInstanceListener