gpt4 book ai didi

c# - 如何更改服务总线队列的属性?

转载 作者:太空宇宙 更新时间:2023-11-03 20:17:08 25 4
gpt4 key购买 nike

我正在使用服务总线队列在 Web 角色和辅助角色之间进行通信。有时,辅助角色不接受 Web 角色消息。但它立即接受我发送的下一条消息。所以我想这可能是因为启用了批量操作而发生的。我一直试图将其设置为 false,但没有成功。这是我的代码。

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;
}

但 EnableBatchedOperations 始终为 true,并且 MaxDeliveryCount 默认情况下始终为 10。

如果您知道问题所在,请告诉我

谢谢

最佳答案

如果您想设置EnabledBatchedOperations,您必须在创建队列之前进行此操作。您可以通过创建 QueueDescription 对象然后将其传递给 CreateQueue 方法来实现。例如:

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

更新:

文档对此非常清楚:

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 表示队列的元数据描述。

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

关于c# - 如何更改服务总线队列的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16017387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com