0
votes

I need to create a queue from which multiple unknown subscribers can get messages.

Each subscriber should only receive each message once and will mark the message complete/abandon but only for themselves. The message would remain on the queue for other subscribers.

Reading the documentation suggests that i need to create a topic and then multiple subscriptions. However, due to architectural reasons. i can't specify in advance what the subscribers are going to be. I want it to be possible for new subscribers to start consuming the messages without having to change my queue config.

Can azure servicebus handle this scenario? Also some of the subscribers will be using the rest client and not the .net client.

Thanks

1

1 Answers

1
votes

Not necessarily a complete answer to this, but yes it’s possible to make Service Bus work in this way providing you stay within the Azure service quota limits.

A client can create its own subscription

string connectionString = CloudConfigurationManager.GetSetting("ServiceBus.ConnectionString");
// Note issue of how you secure this if necessary
var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

if (!namespaceManager.SubscriptionExists(TOPIC_NAME, SUBSCRIPTION_NAME))
{
    //var messagesFilter = new SqlFilter("you can add a client filter for the subscription");
    SubscriptionDescription sd = new SubscriptionDescription(TOPIC_NAME, SUBSCRIPTION_NAME)
    {
        // configure settings or accept the defaults
        DefaultMessageTimeToLive = TimeSpan.FromDays(14),
        EnableDeadLetteringOnMessageExpiration = true,
        MaxDeliveryCount = 1000,
        LockDuration = TimeSpan.FromMinutes(3)
    };
    namespaceManager.CreateSubscription(sd);
    // or namespaceManager.CreateSubscription(sd, messagesFilter);
}
// subscription client for the new topic
_subscriptionClient = SubscriptionClient.CreateFromConnectionString(connectionString, TOPIC_NAME, SUBSCRIPTION_NAME, ReceiveMode.PeekLock);

There is an equivalent in the Rest api https://msdn.microsoft.com/en-us/library/azure/hh780748.aspx

Once the subscription is created the client will be able to receive its own copy of any messages sent to the topic from that point on.

You don’t say how many clients but you will need to stay within the Service Bus service limitations https://azure.microsoft.com/en-us/documentation/articles/service-bus-quotas/

However, you don’t include any information about your application and what the nature of the clients is and there could be many reasons that this is not an advisable solution. Including

Clients will need knowledge of the subscription security keys.
Uncoordinated clients will have to create unique subscription names.
The clients can delete subscriptions when they are finished with them but are you able to ensure that occurs?
Depending on configuration a number of inactive clients could cause your topic to reach its quota limit and stop accepting new messages.
… and probably a lot more

If the clients are not under your control I would say this is definitely not the right solution.