1

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?

Robert N. Dean
  • 1,219
  • 1
  • 14
  • 27

1 Answers1

2

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.

LoekD
  • 11,402
  • 17
  • 27
  • Thanks. Are there other ways to pass CorrelationId by IServiceRemotingClient? – Robert N. Dean Feb 23 '17 at 09:43
  • 1
    Yep, check this: http://stackoverflow.com/questions/34166193/how-to-add-message-header-to-the-request-when-using-default-client-of-azure-serv/34221661#34221661 Using custom implementations of ```IServiceRemotingClient``` and ```ServiceRemotingDispatcher ```. – LoekD Feb 23 '17 at 12:53
  • Thanks a lot for link and help – Robert N. Dean Feb 23 '17 at 15:06