Creating queues

Component: NServiceBus
NuGet Package NServiceBus (4.x)
Standard support for version 4.x of NServiceBus has expired. For more information see our Support Policy.
NServiceBus will automatically request the transport to create queues needed if the installers are enabled. This also includes queues needed by all declared satellites. Prefer the use of scripts to create custom queues instead of relying on interfaces provided by NServiceBus.

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).

public class QueueRegistration :
    IWantQueueCreated
{
    public QueueRegistration(Address queueAddress)
    {
        Address = queueAddress;
    }

    public Address Address { get; }

    public bool IsDisabled => true;

}

public class FeatureThatRequiresAQueue :
    Feature
{
    public override void Initialize()
    {
        Configure.Component(
            componentFactory: () =>
            {
                return new QueueRegistration(Address.Parse("someQueue"));
            },
            lifecycle: DependencyLifecycle.InstancePerCall);
    }

}

Creation

Queues get created during installation time only.

Transports need to implement a custom queue creator.

The queue creation process is always executed sequentially.

Here is a sample of a queue creator

class YourQueueCreator :
    ICreateQueues
{
    public void CreateQueueIfNecessary(Address address, string account)
    {
        // create the queues here
    }

The custom queue creator needs to be registered.

Configure.Component<YourQueueCreator>(DependencyLifecycle.InstancePerCall);

Last modified