通过 RPC 与元数据进行服务结构通信

Service fabric communication by RPC with metadata

API Gateway 应用程序中,我设置为请求 traceId。然后通过 HTTP 将其传递给我的无状态服务。但是服务应该通过 RPC(使用 IServiceRemotingListener)调用另一个服务。我怎样才能将该 traceId 传递给其他服务?

到目前为止我已经完成了(根据 this):

public interface ICommunicationService : IService
{
    Task<string> FooAsync();
}

public class Stateless1 : StatelessService, ICommunicationService 
{
    protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() 
    {
        return new[] { new ServiceInstanceListener(c => this.CreateServiceRemotingListener(c)) };
    }       

    public Task<string> FooAsync()
    {
        return Task.FromResult("TraceId: " + TraceId);
    }
}

并尝试使用它:

ICommunicationService service = ServiceProxy.Create<ICommunicationService>(new Uri("fabric:/App/Stateless1"));

string message = await service.FooAsync();

如何将该 TraceId 传递给其他服务 b RPC?

您只能在 SF 远程处理中使用方法。将 属性 更改为 GetCorrelationId 的方法 returns 它作为 intTask。并添加一个方法:

Task SetCorrelationId( int id){} 

最好,在调用者上生成它并将其作为消息参数的一部分传递给'FooAsync',这样更好,因为它使服务保持无状态。