Disconnect Workers

The Distributor starts sending messages to a Worker once it is aware of it. A Worker registers itself with a Distributor by sending a message containing a SessionID that identifies the current running Worker and the number of messages it can handle concurrently.

Disconnecting a Worker

If the Worker is configured using the NServiceBus.Distributor.MSMQ NuGet, there is a PowerShell cmdlet that can be used to disconnect a Worker from a Distributor. The steps are the following:

  1. Load the NServiceBus PowerShell CmdLet and execute
Remove-NServiceBusMSMQWorker WorkerAddress DistributorAddress TransactionalDistributorQueue

Where:

  • WorkerAddress is the Worker queue name, eg Worker@localhost
  • DistributorAddress is the Distributor queue name eg MyDistributor@localhost, Note: Pass the Distributor queue name, the PowerShell cmdlet will automatically appends ".distributor.control" to the end of the Distributor queue.
  • TransactionalDistributorQueue is the Distributor queue transactional or not ?
  1. Wait for Worker to drain all queued messages from its input queue.
  2. Shutdown the endpoint.

Distributor behavior after the PowerShell is executed

  1. A disconnect message is sent by the PowerShell to the Distributor control queue.
  2. When the Distributor processes it, the Worker with the address specified in the message is set with SessionID disconnected.
  3. Ready messages sent back by the Worker to the Distributor never match the session, so they are skipped and that way the Worker won't receive any more messages from the Distributor.

Last modified