Getting Started
Architecture
NServiceBus
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

MSMQ Subscription Authorization

Component: MSMQ Transport
NuGet Package: NServiceBus.Transport.Msmq (2.x)
Target Version: NServiceBus 8.x

Subscription authorization allows code-level control over what subscribers can subscribe or unsubscribe to.

var routing = endpointConfiguration.UseTransport(new MsmqTransport());

routing.SubscriptionAuthorizer(context =>
{
    var headers = context.MessageHeaders;

    var subscriptionMessageType = headers[Headers.SubscriptionMessageType];

    // messageIntent will be either MessageIntent.Unsubscribe or MessageIntent.Subscribe
    var messageIntent = (MessageIntent)Enum.Parse(typeof(MessageIntent), headers[Headers.MessageIntent], true);

    var endpointName = headers[Headers.SubscriberEndpoint].ToLowerInvariant();

    // true to allow, false to disallow
    return true;
});

Samples