azure - New-AzServiceBusRule cmdlet 随机失败并出现 "already exists"错误

标签 azure azureservicebus azure-powershell azure-servicebus-topics azure-servicebus-subscriptions

我正在尝试自动化我的应用程序的基础设施。作为其中的一部分,仅当服务总线相关资源(命名空间、主题、订阅)不存在时,我才会创建它们。我的订阅只有 1 条规则。因此,每次脚本运行时,它都会删除所有现有规则并从头开始创建此规则。

这是我正在编写的伪代码:

$topic = Get-AzServiceBusTopic -Name $TopicName -NamespaceName $NamespaceName -ResourceGroupName $ResourceGroupName -ErrorVariable notPresent -ErrorAction SilentlyContinue
if ($null -eq $topic -or $notPresent)
{
    $topic = New-AzServiceBusTopic -Name TopicName -NamespaceName NamespaceName -ResourceGroupName ResourceGroupName -ErrorAction Stop
}
$subscription = Get-AzServiceBusSubscription -Name $SubscriptionName -TopicName $TopicName -NamespaceName $NamespaceName -ResourceGroupName $ResourceGroupName -ErrorVariable notPresent -ErrorAction SilentlyContinue
if ($null -eq $subscription -or $notPresent)
{
    $subscription = New-AzServiceBusSubscription -Name SubscriptionName -TopicName TopicName -NamespaceName NamespaceName -ResourceGroupName ResourceGroupName -ErrorAction Stop
}
# forcefully delete existing rules
Get-AzServiceBusRule -SubscriptionName SubscriptionName -TopicName TopicName -NamespaceName NamespaceName -ResourceGroupName ResourceGroupName | Remove-AzServiceBusRule
# create rule
$rule = New-AzServiceBusRule -Name "`$Default"  -SubscriptionName SubscriptionName -TopicName TopicName -NamespaceName NamespaceName -ResourceGroupName ResourceGroupName -FilterType SqlFilter -SqlExpression SqlFilterExpression -ErrorAction Stop

我随机看到 New-AzServiceBusRule Cmdlet 调用失败并出现以下错误:

The messaging entity 'namespacename:Topic:topicname|subscriptionname|$Default' already exists. To know more visit | https://aka.ms/sbResourceMgrExceptions. TrackingId:823eeae9-8776-46e7-90de-5ec305e14bb5_B26, SystemTracker:NoSystemTracker, | Timestamp:2023-05-13T10:33:37

根据New-AzServiceBusRule的文档,cmdlet 创建新规则并更新现有规则。如果是这样,那么为什么我会收到资源存在异常。

我什至尝试等待一秒钟,然后删除所有现有规则并创建新规则,但这也没有帮助。

有趣的是它是随机发生的。对于某些订阅和规则,代码运行得很好,但随机地对于一个奇怪的订阅,它会失败。有时,它根本不会失败!

如何防止这种情况发生?

最佳答案

The messaging entity 'namespacename:Topic:topicname|subscriptionname|$Default' already exists.

按照Document,这个错误不应该出现。我下面的分析清楚地表明这个错误不会出现: 使用$Deafult:

enter image description here

enter image description here

enter image description here

人们可以清楚地看到我也没有收到任何关于我已经存在的不同规则的错误。

如果每当我在其他命令中看到这些错误时,我会将以下命令集成到我的脚本中:

$emo=Get-AzServiceBusRule -SubscriptionName "rithwik" -TopicName "rithwik" -NamespaceName "rithwik1" -ResourceGroupName "rgname"
foreach ($e in $emo.Name)
{
    Remove-AzServiceBusRule -SubscriptionName "rithwik" -TopicName "rithwik" -NamespaceName "rithwik1" -ResourceGroupName "rg name" -Name $e
}
$rule = New-AzServiceBusRule -Name "vammo"  -SubscriptionName "rithwik" -TopicName "rithwik" -NamespaceName "rithwik1" -ResourceGroupName "rgname" -FilterType SqlFilter -SqlExpression '1=1' -ErrorAction Stop

即使使用 $default 也没有收到任何错误:

enter image description here

如果问题仍然存在,我建议您提出支持请求。

关于azure - New-AzServiceBusRule cmdlet 随机失败并出现 "already exists"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76242346/

相关文章:

sql - 在本地运行 Azure 移动服务器项目

azure - 如何记录 Azure 服务总线访问?

c# - 使用 Azure 服务总线重新总线、竞争消费者和 Multi-Tenancy

azure - Connect-AzAccount 无提示

linux - Azure AKS 添加具有不同 Linux 操作系统的节点

azure - 刷新 token azure b2c 不需要 client_secret

javascript - 找不到模块 azure 函数 double_edge.js

python - mktime 参数超出范围

powershell - 通过 Powershell 或 CLI 配置 Azure Web 应用程序部署槽

azure - powershell 让我们加密 Azure Web 应用程序的扩展