Following up on my article titled "Activating queue reader processes on demand", we are launching the External Activator sample. This sample demonstrates how you can build scalable Service Broker applications as executable processes that may be started on demand. The External Activator runs as an NT service and automatically starts a service program (i.e. an EXE that you configure) to read messages from a queue as messages arrive. If the messages arrive quicker than they are being handled by the service program, the External Activator will launch additional instances of the service program upto the configured limit. Service programs normally terminate when they find there are no messages in the queue. Hence, when the arrival rate drops, the number of active queue readers will automatically go down.

The External Activator relies on the “QUEUE ACTIVATION” event notification. It connects to a database and waits for event notification messages to arrive on its queue. Services that require external activation are setup to deliver queue activation events to the External Activator service. When messages arrive on your service’s queue, the queue activation event is fired and a notification message will be delivered to the External Activator service. The External Activator responds to the message by looking at the max number of processes currently running and launching additional instances if required. The External Activator is also resilient to abrupt process shutdown. If it was to die, it has its own recovery mechanism to come back up and restart activating processes.

I thank Ivan Trindev, my teammate and developer on the Service Broker team, for contributing this sample. You can download the binaries and source from the SSB CodeGallery.