0

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

Paul
  • 2,773
  • 7
  • 41
  • 96

1 Answers1

2

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.

Dan Wilson
  • 3,937
  • 2
  • 17
  • 27
  • Ok thanks I was meaning in azure they allow you to see the size in gb – Paul Apr 26 '18 at 19:37
  • You're probably thinking of the `MaxSizeInMegabytes` property. – Dan Wilson Apr 26 '18 at 19:39
  • Hmm thats strange the max size column still shows 16GB? Is that because of the partitioning? – Paul Apr 26 '18 at 20:04
  • The default number of partitions is 16. [Partitioned queues and topics](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-partitioning#standard) – Dan Wilson Apr 26 '18 at 20:15
  • Ok thanks hopefully there is no cost implication to this i guess we billed by the number of messages and their size rather than the queue max size – Paul Apr 26 '18 at 20:17