Question

I have been trying to adapt Rebus in one of my applications. easy to configure, works well everything. Have to implement PUB/SUB communication to achieve responses from multiple sources. so what I made is,

  • Saga(Publisher)

SearchProductSaga : Saga<ProductSagaData>, IAmInitiatedBy<SearchProduct>, IHandleMessages<SearchStarted>, IHandleMessages<SearchProductResponse>, IHandleMessages<SearchCompleted>

Input Queue for Saga is - ProductSaga.Queue

  • Subscriber 1 contains following sequence of execution:

    public class ProductHanderl_1 : IHandleMessage<SearchProduct>
    {
        public void Handle(FullTextSearchProductRequest message)
        {
            Bus.Reply(SearchStarted);
            //Some business logic to find products
            Bus.Reply(AcutalProductResponse);
            Bus.Reply(SearchCompleted);
        }
    }
    
  • Subscriber 2

contains same sequence of execution but a different business logic:

public class ProductHanderl_2 : IHandleMessage<SearchProduct>
{
    public void Handle(FullTextSearchProductRequest message)
    {
        Bus.Reply(SearchStarted);
        //Some business logic to find products
        Bus.Reply(AcutalProductResponse);
        Bus.Reply(SearchCompleted);
    }
}

Now, after this implementation, what I was expecting is: I should be able to calculate number of executing subscribers right now, by receiving SearchStarted messages to SearchProductSaga; and once subscribers done with business logic, would send SearchCompleted message to indicate saga - we are done. And execute MarkAsComplete(); on saga.

But result I'm getting is quite disappointed. What I found is, from handler if you are replying multiple times(like execution sequence in my subscriber logic), all messages are sent together to publisher queue, once handler execution scope ends.

Correct if I'm wrong, and suggest any solution if anyone has. I could achieve same with threading. But I don't want to manage it myself, so is there any asynchronous way to push messages to queue as and when replied from code.

Was it helpful?

Solution

What you're experiencing is a consequence of the fact that a message is handled in a queue transaction in which all outgoing messages are sent as well.

This means that all sent messages, even though they may have been delivered to whichever queueing system you're using, will not be delivered to anyone until the transaction is committed.

This also means that you'd have to divide your saga actions into multiple discrete steps in order to achieve what you're after.

Does that make sense?

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