Note that there are some explanatory texts on larger screens.

plurals
  1. POMultithreading CQRS with NServiceBus
    primarykey
    data
    text
    <p>I am currently investigating using NServiceBus to solve the following problem. I just want to make sure that I am not going down the rabbit hole with this.</p> <p>I have a solution based on a CQRS architecture. Essentially I have a series of commands being delivered to an endpoint via NServiceBus, I perform some processing to alter the state of the aggregate root, then fire off a series of events to notify the rest of the system of the changes.</p> <p>The problem I have is that this all works great on one thread where I do not need to worry about locking down any given aggregate root while I alter the state.</p> <p>We are getting to the point where one thread is not going to cut it and I need to start looking into using multiple worker threads/processes to process the messages.</p> <p>There is a natural task break down based on the fact that I can process multiple aggregate roots at the same time, however I cannot process more than one message for the same aggregate root at the same time, as this will cause high contention due to the speed that the messages are being received.</p> <p>I am trying to avoid the situation where I would need to lock a specific aggregate root id and instead assign an aggregate root to a queue/thread/process which will ensure that all messages from the same aggregate root are processed synchronously.</p> <p>I am using a Pub/Sub model with NServiceBus to publish out the events. The problem as far as I see it is that these events would need to be published from the same endpoint, even though the processing of that message may be delegated to another. i.e. I need to trick the system into thinking that the message was published from "MyDomainQueue" when in fact the message was processed on "MyDomainQueue-Worker1".</p> <p>My plan is to create a custom distributor which will allow the main endpoint to delegate the processing of messages to worker endpoints. The distributor would allocate a queue to any give aggregate root in a round robin fashion. The main endpoint would send commands to these workers, the processing would take place, and the worker would reply with a list of events. The main endpoint would then publish the events back onto the bus.</p> <p>I am looking for some feedback regarding this approach. It feels like I am working a bit to hard to get this to work and I just want to check if any one else has dealt with a similar problem. Perhaps NServiceBus is the wrong tool for the job, or perhaps my approach is just wrong. Any and all feedback is welcome.</p> <p>Thanks,</p> <p>PS - I also have concerns around the amount of configuration which will be required for the solution described above.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload