访问有状态服务 [英] Accessing a stateful service

查看:99
本文介绍了访问有状态服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究Azure的Service Fabric可靠服务,并也在研究示例.

I have been researching Azure's Service Fabric Reliable Services and looking at the samples too.

我现在正在构建带有建议设置的简单概念验证应用程序:一种无状态Web API服务,其背后有一个有状态服务(1个分区).

I am now building a simple proof-of-concept application with a recommended setup: A stateless Web API service with a stateful service behind (1 partition).

我一直在兜圈子,试图找到API服务与背后的有状态服务进行对话的最简单方法.看来该状态服务也必须使用Web API公开(如示例WordCount应用程序所示).

I've been going round in circles trying to find the easiest way for the API service to talk to the stateful service behind. It looks like the stateful service will have to exposed using Web API too (as shown in the example WordCount app).

我是否正确地认为,为了使用有状态服务,它需要使用示例中的OwinCommunicationListener : ICommunicationListener之类的东西通过HTTP/WCF等公开自身?

Am I correct thinking that in order to consume a stateful service it needs to expose itself via HTTP/WCF etc. using something like OwinCommunicationListener : ICommunicationListener from the examples?

推荐答案

当服务位于同一应用程序中时,您可以访问服务实例,例如:

When the services lives inside the same app, you can access the service instance something like:

    public static MyServices.Interfaces.IMyStatefulService GetMyStatefulService()
    {
        var proxyLocation = new ServiceUriBuilder("MyStatefulService");
        var partition = new ServicePartitionKey(1); //provide the partitionKey for stateful services. for stateless services, you can just comment this out
        return ServiceProxy.Create<MyServices.Interfaces.IMyStatefulService>(proxyLocation.ToUri(), partition);
    }

ServiceProxy来自Microsoft.ServiceFabric.Services.Remoting.Client命名空间.

ServiceProxy is from the Microsoft.ServiceFabric.Services.Remoting.Client namespace.

您的界面代码将类似于:

And you interface code will look something like:

public interface IMyStatefulService : IService
{
    Task<MyResponseResult> DoSomething(MyRequest request);
}       

这篇关于访问有状态服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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