Question

I am using MassTransit and have the following-ish code in my app:

RequestMsg request = buildMeARequest();               
SomeTypeOfResponse response = null;

_serviceBus.PublishRequest(request, c =>
    {
        c.Handle<SomeTypeOfResponse>(message => response = message);
        c.SetTimeout(TimeSpan.FromSeconds(30));
    });

return response;

And on the consumer side, I have something like this:

public class RequestMsgConsumer : Consumes<T>.All
{
    public RequestMsgConsumer(IServiceBus serviceBus)
    {

        _serviceBus = serviceBus;
    }

    public void Consume(RequestMsg request)
    {
        SomeTypeOfResponse response = doWorkToGetResponse(request);

        _serviceBus.Context().Publish(response);
    }
}

This works great when everything goes well ... however if the doWorkToGetResponse(request) throws an exception (or any portion of the Consume() method really) the original requestor times out, there is no indication of failure.

My original idea was to build a class like Either<Exception, SomeTypeOfResponse> so that the requester always expects this Either<> construct, but that is going to force me to always try/catch every consume method - and there are plenty of them.

Has anybody else solved this more elegantly?

Was it helpful?

Solution

I believe what you want is to add c.HandleFault(fault => ...) to your PublishRequest.

If that doesn't work, there's been a couple messages on the mailing list this past week or two on how some fixes will be in the next release. I think the failures was limited to Sagas but I could be wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top