客户端正在尝试连接到 Service Fabric ServiceProxy 上的无效地址
Client is trying to connect to invalid address on Service Fabric ServiceProxy
我在 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();
}))
};
}
当我使用此代码在 Asp.net Core 2.0 无状态服务中调用我的服务时:
var service = ServiceProxy.Create<IStorageService>(new Uri("fabric:/MyCluster/Storage"), new ServicePartitionKey(Fnv1aHashCode.Get64bitHashCode(User.Id)));
await service.MyMethod();
调用 "MyMethod"
时出现异常
客户端正在尝试连接到无效地址 http://localhost:58352/etc..
Service Fabric Explorer 中存在异常中的 url,并且端口和 PartitionKey 正确。
没有在 ServiceManifest 中设置端点,因为有状态服务基本上只是根据上面的教程添加 IService 接口和 MyMethod 方法的模板。
我在这里缺少什么?
Asp.net Core 2.0 的文档不是最新的。
我尝试不使用分区,设置 ServicePartitionKey(0)
但结果相同。
我不知道如何进行。
您正在混合两个完全不同的通信堆栈:
- 在您的服务中,您正在使用 bootstraps an ASP.NET Core application 公开 HTTP 端点的 KestrelCommuniactionListener。
- 在您的客户端中,您使用的是 ServiceProxy,它使用完全不同的 binary RPC protocol。
你不能把两者混为一谈。您需要使用 HTTP 客户端与服务的 HTTP 端点对话。有一个 HTTP reverse proxy in Service Fabric that will perform service discover and request forwarding for you to make it easier. There is also a DNS service 允许您使用简单的 DNS 名称寻址其他服务。
在您引用的教程中,后端服务使用服务远程侦听器公开 RPC 端点供 ServiceProxy 连接到:
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new List<ServiceReplicaListener>()
{
new ServiceReplicaListener(
(context) =>
this.CreateServiceRemotingListener(context))
};
}
我在 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();
}))
};
}
当我使用此代码在 Asp.net Core 2.0 无状态服务中调用我的服务时:
var service = ServiceProxy.Create<IStorageService>(new Uri("fabric:/MyCluster/Storage"), new ServicePartitionKey(Fnv1aHashCode.Get64bitHashCode(User.Id)));
await service.MyMethod();
调用 "MyMethod"
时出现异常客户端正在尝试连接到无效地址 http://localhost:58352/etc..
Service Fabric Explorer 中存在异常中的 url,并且端口和 PartitionKey 正确。 没有在 ServiceManifest 中设置端点,因为有状态服务基本上只是根据上面的教程添加 IService 接口和 MyMethod 方法的模板。
我在这里缺少什么? Asp.net Core 2.0 的文档不是最新的。
我尝试不使用分区,设置 ServicePartitionKey(0)
但结果相同。
我不知道如何进行。
您正在混合两个完全不同的通信堆栈:
- 在您的服务中,您正在使用 bootstraps an ASP.NET Core application 公开 HTTP 端点的 KestrelCommuniactionListener。
- 在您的客户端中,您使用的是 ServiceProxy,它使用完全不同的 binary RPC protocol。
你不能把两者混为一谈。您需要使用 HTTP 客户端与服务的 HTTP 端点对话。有一个 HTTP reverse proxy in Service Fabric that will perform service discover and request forwarding for you to make it easier. There is also a DNS service 允许您使用简单的 DNS 名称寻址其他服务。
在您引用的教程中,后端服务使用服务远程侦听器公开 RPC 端点供 ServiceProxy 连接到:
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new List<ServiceReplicaListener>()
{
new ServiceReplicaListener(
(context) =>
this.CreateServiceRemotingListener(context))
};
}