Operational Scripting for Azure Service Bus - issue creating queue

Hey there,

We’re starting to use the Particular ecosystem, we’re using the Azure Functions preview stuff and Azure Service Bus as transport and it works really good. Ofcourse there is the limitation that they are unable to use the installer. So we’ve adopted operational scripting for Azure Service Bus.


We use it in our pipeline, and create the queues, logical endpoints and subscriptions that we need.
The creation of endpoints and subscriptions is idempotent, it will first check if it already exists.
The creation of queues is not! :frowning:

It will throw an exception. Is this something that can be changed to be idempotent as well?

The script I execute is shown below.

asb-transport.exe endpoint create Adapter.Klant -c $connectionString
asb-transport.exe endpoint create Domein.Hr -c $connectionString

Write-Output "Subscribing Klant adapter to medewerker events..."
asb-transport.exe endpoint subscribe Adapter.Klant Bedrijf.Hr.Messages.MedewerkerCreated -c $connectionString
asb-transport.exe endpoint subscribe Adapter.Klant Bedrijf.Hr.Messages.MedewerkerDeleted -c $connectionString
asb-transport.exe endpoint subscribe Adapter.Klant Bedrijf.Hr.Messages.MedewerkerUpdated -c $connectionString

Write-Output "Create error and audit queues"
asb-transport.exe queue create error -c $connectionString
asb-transport.exe queue create audit -c $connectionString

The output from my task is provided below.

Creating logical endpoints...
Queue 'McMaster.Extensions.CommandLineUtils.CommandArgument' already exists, skipping creation
Topic 'McMaster.Extensions.CommandLineUtils.CommandOption' already exists, skipping creation
Subscription 'McMaster.Extensions.CommandLineUtils.CommandArgument' already exists, skipping creation
Endpoint 'Adapter.Klant' is ready.
Queue 'McMaster.Extensions.CommandLineUtils.CommandArgument' already exists, skipping creation
Topic 'McMaster.Extensions.CommandLineUtils.CommandOption' already exists, skipping creation
Subscription 'McMaster.Extensions.CommandLineUtils.CommandArgument' already exists, skipping creation
Endpoint 'Domein.Hr' is ready.
Subscribing Klant adapter to medewerker events...
Rule 'McMaster.Extensions.CommandLineUtils.CommandArgument' for topic 'McMaster.Extensions.CommandLineUtils.CommandOption' and subscription 'McMaster.Extensions.CommandLineUtils.CommandOption' already exists, skipping creation. Verify SQL filter matches '[NServiceBus.EnclosedMessageTypes] LIKE '%Bedrijf.Hr.Messages.MedewerkerCreated%'.
Endpoint 'Adapter.Klant' subscribed to 'Bedrijf.Hr.Messages.MedewerkerCreated'.
Rule 'McMaster.Extensions.CommandLineUtils.CommandArgument' for topic 'McMaster.Extensions.CommandLineUtils.CommandOption' and subscription 'McMaster.Extensions.CommandLineUtils.CommandOption' already exists, skipping creation. Verify SQL filter matches '[NServiceBus.EnclosedMessageTypes] LIKE '%Bedrijf.Hr.Messages.MedewerkerDeleted%'.
Endpoint 'Adapter.Klant' subscribed to 'Bedrijf.Hr.Messages.MedewerkerDeleted'.
Rule 'McMaster.Extensions.CommandLineUtils.CommandArgument' for topic 'McMaster.Extensions.CommandLineUtils.CommandOption' and subscription 'McMaster.Extensions.CommandLineUtils.CommandOption' already exists, skipping creation. Verify SQL filter matches '[NServiceBus.EnclosedMessageTypes] LIKE '%Bedrijf.Hr.Messages.MedewerkerUpdated%'.
Endpoint 'Adapter.Klant' subscribed to 'Bedrijf.Hr.Messages.MedewerkerUpdated'.
Create error and audit queues
asb-transport.exe : Command failed with exception (MessagingEntityAlreadyExistsException): SubCode=40900. Conflict. 
You're requesting an operation that isn't allowed in the resource's current state. To know more visit 
https://aka.ms/sbResourceMgrExceptions. . TrackingId:a618e317-a0af-40f1-85b6-49f40448b76c_G4, 
SystemTracker:xxxxxxxxxxxxxxx.error, Timestamp:2020-09-23T07:28:06
At D:\a\1\src\nservicebus.ps1:13 char:1
+ asb-transport.exe queue create error -c $connectionString
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Command failed ...-09-23T07:28:06:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
##[error]PowerShell exited with code '1'.
Finishing: Create NServiceBus queues and topics

Hi Rob,

Great to hear that you find NServiceBus with Azure Service Bus and Functions a good combination.
Regarding your question:

Is this something that can be changed to be idempotent as well?

The behaviour is intentional and as designed. The rationale to throw upon queue creation is to avoid a scenario where a queue creation is attempted and the queue already exists, leading to incorrectly configured queue in production. For example, NServiceBus does not work with Message Sessions. And if a queue is created with sessions enabled and the operation will not throw, you have no indication that it won’t be usable. Or, worse scenario, a queue that will be misconfigured and won’t be obvious until production issues. For example, the lock duration that is not set to the maximum value or low max delivery count.

I see two options here:

  1. You need to customize the behaviour of the tool. Forking and modifying behaviour is possible. You can achieve that by wrapping this code within a try/catch block to swallow the exception. Similar to what the endpoint creation code does here.
  2. Modify your script to delete and then create the queues.

If none of these options works for you, you can raise an issue in the issue tracker but be prepared to justify why the rationale described above should be questioned.

Thank you,
Sean Feldman

Thanks for your reply. I understand the rationale, but I think you should then apply this to the endpoint as well. It doesn’t make sense to do both.

image

Creating a queue is part of creating an endpoint and you will have the same issues that you are describing when the queues were created with different setup.

Deleting the queue is not the answer for me, as I don’t want to lose messages. I’ll raise in issue in the issue tracker, I think the rationale should be applied to both situations the same.

Hi Rob,

Thank you for raising the issue. It will be triaged and prioritized.

Thank you,
Sean Feldman

1 Like