Creating queues

Component: NServiceBus | Nuget: NServiceBus (Version: 6.x)

The scripting guidelines shows how to take full control over queue creation:

Declaration

Queues should be declared during the Setup phase of a Feature.

A built-in example is the audit feature which needs the audit queue. During start-up NServiceBus ensures the declared queues are present and aborts the start-up procedure if they are not (with an exception of MSMQ remote queues which are optional).

Edit
public class FeatureThatRequiresAQueue :
    Feature
{
    protected override void Setup(FeatureConfigurationContext context)
    {
        var queueBindings = context.Settings.Get<QueueBindings>();
        queueBindings.BindReceiving("someQueue");
    }
}

Creation

Queues get created during installation time only.

Transports need to implement a custom queue creator.

It is the responsibility of the queue creator to either sequentially or concurrently create the queues provided in the queue bindings for the specified identity.

Here is a sample of a queue creator

Edit
class YourQueueCreator :
    ICreateQueues
{
    public async Task CreateQueueIfNecessary(QueueBindings queueBindings, string identity)
    {
        // create the queues here
    }

The custom queue creator needs to be registered.

Edit
configuration.RegisterComponents(
    registration: components =>
    {
        components.ConfigureComponent<YourQueueCreator>(DependencyLifecycle.InstancePerCall);
    });

Last modified