C# RPC与元数据的服务结构通信
在C# RPC与元数据的服务结构通信,c#,azure,rpc,microservices,azure-service-fabric,C#,Azure,Rpc,Microservices,Azure Service Fabric,在API网关应用程序中,我设置为请求traceId。然后通过HTTP将其传递给我的无状态服务。但是服务应该通过RPC(使用IServiceRemotingListener)调用另一个服务。我如何将该traceId传递给其他服务 到目前为止,我已经完成了(根据): 公共接口ICommunicationService:iSeries设备 { 任务fooancy(); } 公共类无状态1:无状态服务,ICommunicationService { 受保护的重写IEnumerable CreateSer
API网关
应用程序中,我设置为请求traceId。然后通过HTTP
将其传递给我的无状态服务。但是服务应该通过RPC
(使用IServiceRemotingListener
)调用另一个服务。我如何将该traceId传递给其他服务
到目前为止,我已经完成了(根据):
公共接口ICommunicationService:iSeries设备
{
任务fooancy();
}
公共类无状态1:无状态服务,ICommunicationService
{
受保护的重写IEnumerable CreateServiceInstanceListeners()
{
返回new[]{new ServiceInstanceListener(c=>this.CreateServiceRemotingListener(c))};
}
公共任务fooancy()
{
返回Task.FromResult(“TraceId:+TraceId”);
}
}
并尝试使用它:
ICommunicationService service = ServiceProxy.Create<ICommunicationService>(new Uri("fabric:/App/Stateless1"));
string message = await service.FooAsync();
ICommunicationService=ServiceProxy.Create(新Uri(“结构:/App/Stateless1”);
string message=wait service.fooancy();
如何将该TraceId传递给其他服务b RPC?您只能在SF远程处理中使用方法。将属性更改为方法
GetCorrelationId
,该方法将其作为int
的Task
返回。并添加一个方法:
Task SetCorrelationId( int id){}
或者最好在调用方上生成它,并将其作为消息参数的一部分传递给更好的'fooancy',因为它使服务保持无状态。谢谢。IServiceRemotingClient传递CorrelationId还有其他方法吗?是的,请检查:使用
IServiceRemotingClient
和ServiceRemotingDispatcher
的自定义实现。非常感谢链接和帮助
Task SetCorrelationId( int id){}