英文:
New-AzServiceBusRule cmdlet randomly failing with "already exists" error
问题
I am trying to automate the infrastructure of my application. As part of that, I am creating Service Bus related resources (Namespace, Topics, Subscriptions) only if they do not exist. My subscriptions will only have 1 rule. So every time the script runs, it will delete all existing rules and create this rule from scratch.
Here's the pseudo code I am writing:
$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
Randomly I am seeing New-AzServiceBusRule
Cmdlet call fails with the following error:
> 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
According to the documentation of New-AzServiceBusRule
, the cmdlet either creates a new rule and updates an existing rule. If that is the case, then why am I getting the resource exists exception.
I even tried waiting for a second before deleting all existing rules and creating the new rule but that did not help either.
Interesting thing is that it happens randomly. For some of the Subscriptions and Rules, the code works just fine and then randomly for one odd Subscription, it would fail. At times, it will not fail at all!
How can I prevent this from happening?
随机出现 New-AzServiceBusRule
命令失败,显示以下错误:
> 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
的文档,该命令创建新规则并更新现有规则。如果是这种情况,那么为什么会出现资源已存在的异常呢?
我甚至尝试在删除所有现有规则并创建新规则之前等待一秒钟,但也没有帮助。
有趣的是,这是随机发生的。对于某些订阅和规则,代码运行得很好,但是随机地出现一个奇怪的订阅会失败。有时候,它根本不会失败!
我该如何防止这种情况发生?
英文:
I am trying to automate the infrastructure of my application. As part of that, I am creating Service Bus related resources (Namespace, Topics, Subscriptions) only if they do not exist. My subscriptions will only have 1 rule. So every time the script runs, it will delete all existing rules and create this rule from scratch.
Here's the pseudo code I am writing:
$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
Randomly I am seeing New-AzServiceBusRule
Cmdlet call fails with the following error:
> 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
According to the documentation of New-AzServiceBusRule
, the cmdlet either creates a new rule and updates an existing rule. If that is the case, then why am I getting the resource exists exception.
I even tried waiting for a second before deleting all existing rules and creating the new rule but that did not help either.
Interesting thing is that it happens randomly. For some of the Subscriptions and Rules, the code works just fine and then randomly for one odd Subscription, it would fail. At times, it will not fail at all!
How can I prevent this from happening?
答案1
得分: 1
以下是您要翻译的内容:
"The messaging entity 'namespacename:Topic:topicname|subscriptionname|$Default' already exists.
This error shouldn't come, as per Document and my analysis below is clearly says that this error will not come:
With $Deafult
:
One can clearly see I hadn't received any error for different rules too that are already existing with me.
If whenever I see these errors in other commands i integrate below commands into my script:
$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
Even with $default not getting any error:
If the issue still persists, I would suggest you to raise a support request."
英文:
>The messaging entity 'namespacename:Topic:topicname|subscriptionname|$Default' already exists.
This error shouldn't come, as per Document and my analysis below is clearly says that this error will not come :
With $Deafult
:
One can clearly see I hadn't received any error for different rules too that are already existing with me.
If whenever I see these errors in other commands i integrate below commands into my script:
$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
Even with $default not getting any error :
If the issue still persists , I would suggest you to raise a support request.
答案2
得分: 0
我在几个月前向Azure支持提出了有关此问题的工单,他们只是告诉我他们预计修复将在下周末之前完全部署。
英文:
I opened a ticket to Azure support about this topic some months ago and they just told me they expect a fix to be fully deployed by the end of next week.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论