Paul
Paul

Reputation: 3293

Azure Service bus Queue creation in C# does not set EnablePartioning or size?

I have the code below for creating a queue in Azure service Bus

        var cs = azureServiceBusConnectionString;
        var namespaceManager = NamespaceManager.CreateFromConnectionString(cs);
        if (namespaceManager.QueueExists(queueName))
        {
            namespaceManager.DeleteQueue(queueName);
        }

        var que = namespaceManager.CreateQueue(queueName);
        que.EnablePartitioning = true;

My queue is created ok but I have 2 questions

1) Even though I set EnablePartioning to true my queue has EnablePartioning set to false. Why is this? Is there a method I have to call to save the changes or something 2) I cant set the size of the queue as the SizeInBytes property is read only. How can I do that?

I dont see any constructor that allows me to set EnablePartitioning or the size?

Paul

Upvotes: 0

Views: 493

Answers (1)

Dan Wilson
Dan Wilson

Reputation: 4057

You should enable partitioning on a QueueDescription when creating the queue.

var cs = azureServiceBusConnectionString;
var namespaceManager = NamespaceManager.CreateFromConnectionString(cs);
if (namespaceManager.QueueExists(queueName))
{
    namespaceManager.DeleteQueue(queueName);
}

var queueDescription = new QueueDescription(queueName);
queueDescription.EnablePartitioning = true;
queueDescription.MaxSizeInMegabytes = 1024;

var que = namespaceManager.CreateQueue(queueDescription);

You cannot set SizeInBytes because it is based on the number and size of messages in the queue. It wouldn't make any sense to set it.

You can set the maximum queue size using the MaxSizeInMegabytes property.

Upvotes: 2

Related Questions