Fra*_*llo 4 azure-service-fabric service-fabric-stateful
我在Service Fabric 6上有一个Asp.net Core 2.0无状态服务和一个Asp.net Core 2.0状态服务,有10个分区计数.
我按照本教程
https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-add-a-web-frontend
我遵循所有步骤,除了我在Visual Studio中使用模板,其中CreateServiceReplicaListeners使用KestrelCommunicationListener
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new ServiceReplicaListener[]
{
new ServiceReplicaListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, (url, listener) =>
{
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<StatefulServiceContext>(serviceContext)
.AddSingleton<IReliableStateManager>(this.StateManager))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
.UseUrls(url)
.Build();
}))
};
}
Run Code Online (Sandbox Code Playgroud)
当我使用以下代码在Asp.net Core 2.0无状态服务中调用我的服务时:
var service = ServiceProxy.Create<IStorageService>(new Uri("fabric:/MyCluster/Storage"), new ServicePartitionKey(Fnv1aHashCode.Get64bitHashCode(User.Id)));
await service.MyMethod();
Run Code Online (Sandbox Code Playgroud)
调用"MyMethod"时会出现异常
客户端试图连接到无效的地址的http://本地主机:58352 /等 ..
异常中存在的URL存在于Service Fabric Explorer中,并且Port和PartitionKey是正确的.ServiceManifest中没有设置端点,因为有状态服务基本上只是添加了IService接口和MyMethod方法的模板,如上所述.
我在这里缺少什么?Asp.net Core 2.0的文档不是最新的.
我试图不使用分区,设置 ServicePartitionKey(0)但结果相同.
我不知道该怎么办.
您正在混合两个完全不同的通信堆栈:
你不能把两者混在一起.您需要使用HTTP客户端与服务的HTTP端点进行通信.Service Fabric中有一个HTTP 反向代理,它将为您执行服务发现和请求转发,以使其更容易.还有一个DNS服务,允许您使用简单的DNS名称来解决其他服务.
在您引用的教程中,后端服务使用Service Remoting侦听器,该侦听器公开ServiceProxy的RPC端点以连接到:
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new List<ServiceReplicaListener>()
{
new ServiceReplicaListener(
(context) =>
this.CreateServiceRemotingListener(context))
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
708 次 |
| 最近记录: |