I'm trying to implement a simple POC for a NServiceBus solution. So I implemented 3 endpoints, let's call them A,B and C. A is self hosted in a console app, B and C are NSB hosts. In A I'm sending a command DoFoo, in B I'm handling DoFoo and inside the handler I publish several events of type BarOccurred like so:
for (int i=0; i<5; i++)
{
Bus.Publish(new BarOccurred);
Thread.Sleep(1000);
}
In C I'm subscribing and handling it by writing to the console that Bar occurred.
I expected to see the message handled in C every time that B publishes it (i.e every second). However the behavior I see is that only after the command handler exit (after 5 iterations) only then all 5 messages are received by C.
Is that the expected behavior for the default configuration? Is there anything I need to declare in order to have messages sent and processed as soon as they are published?
The Bus.Publish is in a single transaction and commits once all messages have been sent. I would see if packaging all the messages in one Bus.Publish(IMesssage[]) may meet your needs. This turns into 1 message on the wire.