[英]Service fabric communication by RPC with metadata
在API Gateway
應用中,我設置為請求traceId。 然后通過HTTP
將其傳遞給我的無狀態服務。 但是服務應該通過RPC
調用另一個服務(使用IServiceRemotingListener
)。 如何將traceId傳遞給其他服務?
我這樣做的遠(根據此 ):
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
,將其作為int
Task
返回。 並添加一個方法:
Task SetCorrelationId( int id){}
或者最好在調用方上生成它,並將其作為消息參數的一部分傳遞給“ FooAsync”,因為更好的做法是,它將服務保持無狀態。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.