簡體   English   中英

通過RPC與元數據進行服務結構通信

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM