How to change the properties of a service bus queue?

試著忘記壹切 提交于 2019-12-23 03:30:55

问题


I am using service bus queues to communicate between web role and worker role. Sometimes web role messages are not being accepted by worker role. But it immediately accepts the next message i send. So i was thinking maybe its happening because the Batched Operations is enabled. I have been trying to put it to false but i havent been successful. This is my code.

public static QueueClient GetServiceBusQueueClient(string queuename)
    {            
        string connectionString;

        if (RoleEnvironment.IsAvailable)
         connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
        else
            connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];          


        var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

        QueueDescription queue = null;

        if (!namespaceManager.QueueExists(queuename))
        {
            queue = namespaceManager.CreateQueue(queuename);
            queue.EnableBatchedOperations = false;
            queue.MaxDeliveryCount = 1000;
        }
        else
        {
            queue = namespaceManager.GetQueue(queuename);
            queue.EnableBatchedOperations = false;
            queue.MaxDeliveryCount = 1000;
        }

        MessagingFactorySettings mfs = new MessagingFactorySettings();
        mfs.NetMessagingTransportSettings.BatchFlushInterval = TimeSpan.Zero;

        string issuer;
        string accessKey;
         if (RoleEnvironment.IsAvailable)
            issuer = RoleEnvironment.GetConfigurationSettingValue("AZURE_SERVICEBUS_ISSUER");
         else
             issuer = ConfigurationManager.AppSettings["AZURE_SERVICEBUS_ISSUER"];

        if (RoleEnvironment.IsAvailable)
            accessKey = RoleEnvironment.GetConfigurationSettingValue("AZURE_SERVICEBUS_ACCESS_KEY");
        else
            accessKey = ConfigurationManager.AppSettings["AZURE_SERVICEBUS_ACCESS_KEY"];

        mfs.TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuer, accessKey);
        MessagingFactory messagingFactory = MessagingFactory.Create(namespaceManager.Address, mfs);

        QueueClient Client = messagingFactory.CreateQueueClient(queue.Path);            

        return Client;
    }

But the EnableBatchedOperations is always true and the MaxDeliveryCount is always 10 by default.

Let me know if you know what's the issue

Thanks


回答1:


If you want to set the EnabledBatchedOperations, you have to do that before you create the queue. you do that by creating a QueueDescription object then pass that to the CreateQueue method. For example:

QueueDescription orderQueueDescription =
    new QueueDescription(queuename)
    {
        RequiresDuplicateDetection = true,
        MaxDeliveryCount = 1000,
    };
namespaceMgr.CreateQueue(orderQueueDescription);

Update:

The documentation is pretty clear on this:

Since metadata cannot be changed once a messaging entity is created, modifying the duplicate detection behavior requires deleting and recreating the queue. The same principle applies to any other metadata. [1]

QueueDescription Represents the metadata description of the queue.

[1] http://msdn.microsoft.com/en-us/library/windowsazure/hh532012.aspx




回答2:


Update Azure SDK 2.3

UpdateQueue method on the NamespaceManager still doesn't let you update any properties apart from suspending or resuming the queue.

If you need to change MaxDeliveryCount on an existing queue and you don't want to delete and recreate the queue, your only option is to change it in the Azure portal.



来源:https://stackoverflow.com/questions/16017387/how-to-change-the-properties-of-a-service-bus-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!