2017-02-22 50 views
0

在设置为请求traceId的API Gateway应用程序中。然后通过HTTP传递给我的无状态服务。但服务应通过RPC(使用IServiceRemotingListener)调用另一项服务。我怎样才能将traceId传递给其他服务?通过RPC与元数据进行服务结构通信

我到目前为止已经进行(根据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?

回答

1

您只能在SF远程处理中使用方法。将该属性更改为方法GetCorrelationId,将其返回为Taskint。和添加的方法:

Task SetCorrelationId(int id){} 

或者优选,生成它的调用者,并将其传递作为消息参数“FooAsync”,这是更好的,因为它使该服务无状态的一部分。

+0

谢谢。是否有其他方式通过IServiceRemotingClient传递CorrelationId? –

+1

是的,请检查:http://stackoverflow.com/questions/34166193/how-to-add-message-header-to-the-request-when-using-default-client-of-azure-serv/34221661# 34221661使用''''IServiceRemotingClient'''和'''ServiceRemotingDispatcher '''的自定义实现。 – LoekD

+0

非常感谢您的联系和帮助 –

相关问题