Request/Response monitoring extensibility points

19 views
Skip to first unread message

Robert Slaney

unread,
Jun 7, 2018, 8:08:29 PM6/7/18
to masstransit-discuss
We are upgrading from 3.5.x to 5.x and in the process of refactoring our MT proxies.

At the moment we have tightly coupled metrics and logging in our proxies, in that we wrap Bus.PublishRequest<T> call in a using statements, await the response task and handle completion on the dispose.  I would like to make this transparent and use MT's pipelines/observers instead, but I can't work out the correct extensibility points to use ( on the IBus, IRequestClient , and/or RequestHandle).  For example I need to measure timing ( from the publishing app's perspective ) of a request/response pair or log request/response events using information from both messages.

Any guidance would be appreciated.

3.5.x
protected async Task<TRequest, TResponse>( TRequest request )
{
   using( var timer = ... )
   using( logger.BeginScope(request))
   
{
       
Request<TRequest> request = await this.bus.PublishRequest<TRequest>( request, context =>
       
{
           context
.Handle<TResponse>( value => ... );
           context
.Handle<Fault>( value => ... );
       
});

       await request
.Task;

       
// operation completed
  }
}

5.x

protected async Task<TRequest, TResponse>( TRequest request )
{
  var requestClient = this.Bus.CreateRequestClient<TMessage>();
  using (var handle = requestClient.Create(message))
  {
    var responseHandle = await handle.GetResponse<TResponse>();
    return responseHandle.Message;
     }
}



Reply all
Reply to author
Forward
0 new messages