MSMQ Subscription Authorization

Component: MSMQ Transport
NuGet Package NServiceBus.Transport.Msmq (2-pre)
Target NServiceBus Version: 8.x
This page targets a pre-release version and is subject to change prior to the final release.

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];
    var messageIntent = headers[Headers.MessageIntent];
    var messageIntentEnum = (MessageIntentEnum) Enum.Parse(typeof(MessageIntentEnum), messageIntent, true);
    // messageIntentEnum will be either MessageIntentEnum.Unsubscribe or MessageIntentEnum.Subscribe
    var endpointName = headers[Headers.SubscriberEndpoint]
        .ToLowerInvariant();
    // true to allow, false to decline
    return true;
});

Samples


Last modified