nservicebusnservicebus-distributor

NServiceBus Distributor: Preventing extra entries in StorageQueue after Client restart


For simplicity, I'll refer to both the distributor's ControlInputQueue and it's StorageQueue as the same. I understand how the distributor's client notifies of it's availabilty by writing an entry to the ControlInputQueue and how the distributor moves the entry to it's StorageQueue to track which clients are available to do work. It's just easier to explain if I treat them as the same. So...

I've created a proof of concept to demonstrate the behavior of the NServiceBus distributor. As expected, when a client starts up, it adds an entry to the distributor's StorageQueue. When a message comes in to the distributor (via it's InputQueue), the distributor removes an entry from it's StorageQueue, and forwards the message to the indicated client. The client performs it's work, and then adds an entry back to the distributor's StorageQueue. Thus there is at most one entry (per client) in the distributor's StorageQueue.

My problem occurs when a client is shut down, either manually or unexpectedly (like the server explodes). The client's entry still exists in the Distributor's StorageQueue, so as far as the distributor knows, that client is still available. This is fine, except that when the client starts up again, it adds another entry to the StorageQueue. So now there are two entries in the StorageQueue for a single client.

Is there any way to ensure that the distributor only ever has one StorageQueue entry for any given client?


Solution

  • In the interests of providing an "official" answer to this question... Per Andreas' comment above, it seems that there isn't a way to prevent these duplicate entries in NServiceBus v2.6, but there is in v3.0. So the solution is to upgrade. ;-)