服务结构不止一个用于服务远程的通信侦听器 [英] Service fabric more than one communication listener for service remoting

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

问题描述

我正在使用Azure Service Fabric开发一些微服务.我有一些用例需要微服务之间的通信,并且阅读了有关服务远程处理的信息

I am developing few micro services using Azure Service Fabric. I have some use cases which need the communication between micro services and I read about service remoting https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting. I just wanted to know is it possible to support more than one listeners in a SF application. E.g. I have an existing stateless web api SF application which is having a listener like below

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        return new ServiceInstanceListener[]
        {
            new ServiceInstanceListener(serviceContext => new OwinCommunicationListener(Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, "ServiceEndpoint"))
        };
    }

在上面的列表中,我需要添加一个ServiceRemotingListener,以便可以为其他人公开一些来自Micro服务的数据.方法是否可能或有任何错误.我已经完成了基于反向代理的通信,但是有点担心性能(因为我计划执行从服务1到服务2的实时读取操作).

To the above list, I need to add a ServiceRemotingListener so that I can expose some data from Micro service for others. Is it possible or anything wrong with approach. I have done the Reverse proxy based communication, but bit concerned with the performance(since I am planning to perform a real time read operation from Service 1 to Service 2).

推荐答案

在您的CreateServiceInstanceListeners方法中,您将返回一个侦听器数组.这意味着可以创建多个侦听器.只需像添加其他数组一样添加它即可:

In your CreateServiceInstanceListeners method you are returning an array of listeners. This means that it is possible to create multiple listeners. Just add it like you would with any other array:

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
    return new ServiceInstanceListener[]
    {
        new ServiceInstanceListener(serviceContext => this.CreateServiceRemotingListener(serviceContext), "RemotingListener"),
        new ServiceInstanceListener(serviceContext => new OwinCommunicationListener(Startup.ConfigureApp, serviceContext, ServiceEventSource.Current, "ServiceEndpoint"))
    };
}

请注意,即使侦听器名称是可选参数,您也必须必须为侦听器命名.服务代理尝试连接到另一个端点时,我也遇到了一些问题.为了解决此问题,请首先声明远程侦听器,然后再声明其他侦听器.

Note that even though the listener name is an optional parameter, you have to give your listeners a name. I've also experienced some problems with the service proxy trying to connect to the other endpoint. In order to solve this declare the remoting listener first and your other listeners second.

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

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