RestBus icon indicating copy to clipboard operation
RestBus copied to clipboard

Custom DelegatingHandler in HttpConfiguration.MessageHandlers not being called when request is recevide via RabbitMQ

Open neoaisac opened this issue 9 years ago • 1 comments

I have an OWIN WebAPI application. I have a custom 'MyCustomHandler' that inherits from 'DelegatingHandler' and just logs some stuff for every request. An instance of 'MyCustomHandler' is added to the 'HttpConfiguration.MessageHandlers' list before the 'EnsureInitialized' method is called and before the RestBus configuration comes below. The 'HttpConfiguration' object has this handler when RestBus is configured to receive requests via RabbitMQ.

Still, when the request is received, the handler is not triggered, and the request does not go through the SendAsync method of the handler. Why?

public class Startup
{
    public void Configuration(IAppBuilder app)
    {

        var httpConfiguration = new HttpConfiguration();'
        httpConfiguration.MapHttpAttributeRoutes();
        httpConfiguration.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional });

        httpConfiguration.MessageHandlers.Add(new MyCustomHandler("identifier"));

        httpConfiguration.EnsureInitialized();
        app.UseWebApi(httpConfiguration);

        var amqpUrl = "myURL";
        var serviceName = "serviceName";

        var msgMapper = new BasicMessageMapper(amqpUrl, serviceName);
        var subscriber = new RestBusSubscriber(msgMapper);
        var restBusHost = new RestBusHost(subscriber, httpConfiguration);

        restBusHost.Start();
    }
}

neoaisac avatar Sep 18 '15 12:09 neoaisac

This bug is caused by the issue explained at https://github.com/tenor/RestBus/blob/f5b052abeb3ae3b59f04556d51f0bd6c3f33bee2/src/Frameworks/WebApi/RestBus.WebApi/RequestHandler.cs#L67

tenor avatar Dec 19 '15 22:12 tenor