简体   繁体   中英

NServiceBus: Delay processing of all incoming messages

I have a situation where a console app (let's call it the Builder) and an NServiceBus endpoint (let's call it the Feeder) are both writing to the same data store. The Feeder processes EntityChanged messages as they come in, whereas the Builder goes to a database and gets the latest information for all Entities and writes the necessary information to the data store in one huge batch.

A problem that is immediately apparent from looking at how the Builder works is that it will clobber any changes to the data store that the Feeder makes whilst the Builder is running . So, what I need to do is stop the Feeder from processing NSB messages whilst the Builder is running and then for it to simply resume processing when the Builder finishes.

At the moment we devs do this because we run the Builder manually, ad hoc; we literally stop the Feeder service when we're about to run the Builder and then restart it afterwards. Now that we're going to run the Builder on a schedule we need to automate this process.

Stopping the Feeder service in an automated fashion is not ideal because our monitoring and alerting tools will go nuts, and anyway it's a Windows service that's set to restart automatically.

Is there a function in NServiceBus that can accomplish this for us? I originally thought of message Scheduling or Timeouts, but they are specifically configured by the sending endpoint. I need to timeout messages on the receiving endpoint.

Sounds like a relatively simple answer for this would be to check for concurrency issues, so when the feeder goes to commit to the database it will need to check that the data row is still at the same state as when it first read it, otherwise throw a concurrency error. Then NServiceBus would be able to retry after that occurrence. Take a look at this link and it will explain a little more in depth as it sounds like you may need an optimistic locking strategy. http://www.agiledata.org/essays/concurrencyControl.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM