2017-02-22 49 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

非常感謝您的聯繫和幫助 –

相關問題