gpt4 book ai didi

azure-service-fabric - 客户端正在尝试连接到 Service Fabric ServiceProxy 上的无效地址

转载 作者:行者123 更新时间:2023-12-05 00:49:51 26 4
gpt4 key购买 nike

我在 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 Stateless 服务中调用我的服务时:
var service = ServiceProxy.Create<IStorageService>(new Uri("fabric:/MyCluster/Storage"), new ServicePartitionKey(Fnv1aHashCode.Get64bitHashCode(User.Id)));
await service.MyMethod();

调用“MyMethod”时引发异常

客户端正在尝试连接到无效地址 http://localhost:58352/etc ..

异常中存在的 url 存在于 Service Fabric Explorer 中,并且 Port 和 PartitionKey 是正确的。
ServiceManifest 中没有设置端点,因为有状态服务基本上只是添加了 IService 接口(interface)和 MyMethod 方法的模板,如上面的教程。

我在这里缺少什么?
Asp.net Core 2.0 的文档不是最新的。

我尝试不使用分区,设置 ServicePartitionKey(0)但同样的结果。

我不知道该怎么做。

最佳答案

您正在混合两个完全不同的通信堆栈:

  • 在您的服务中,您使用的是 bootstraps an ASP.NET Core application 的 KestrelCommuniactionListener暴露 HTTP 端点。
  • 在您的客户端中,您使用的是 ServiceProxy,它使用完全不同的 binary RPC protocol .

  • 你不能把两者混在一起。您需要使用 HTTP 客户端与服务的 HTTP 端点通信。有一个 HTTP reverse proxy在 Service Fabric 中,它将为您执行服务发现和请求转发以使其更容易。还有一个 DNS service这允许您使用简单的 DNS 名称来处理其他服务。

    在您引用的教程中,后端服务使用一个 Service Remoting 监听器,该监听器公开一个 RPC 端点以供 ServiceProxy 连接到:
    protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
    return new List<ServiceReplicaListener>()
    {
    new ServiceReplicaListener(
    (context) =>
    this.CreateServiceRemotingListener(context))
    };
    }

    关于azure-service-fabric - 客户端正在尝试连接到 Service Fabric ServiceProxy 上的无效地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46683700/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com