In the API Gateway
app I set to request traceId. Then over HTTP
pass it to my stateless service. But service should call another service by RPC
(using IServiceRemotingListener
). How can I pass that traceId to other service?
I've done so far (according to 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);
}
}
and trying to use it:
ICommunicationService service = ServiceProxy.Create<ICommunicationService>(new Uri("fabric:/App/Stateless1"));
string message = await service.FooAsync();
How can I pass that TraceId to other service b RPC?
You can only use methods in SF remoting. Change the property into a method GetCorrelationId
that returns it as Task
of int
. And add a method:
Task SetCorrelationId( int id){}
Or preferably, generate it on the caller and pass it as part of the message argument to 'FooAsync' which is better, because it keeps the service stateless.