Clones a Azure Service Bus by creating a new one and cloning all queues, topics and subscriptions into it, when ready outputs the connectionstring.
Because Azure doesn't have a emulator, use this for automation such as integration tests.
When ready, run again with --delete
to cleanup the temporary Azure resource(s).
PR's and issues are welcome.
- Docker.
- Azure service principal with Azure Service Bus Data Owner and Contributor on subscription level or replace Contributor with a custom one with resource group write/read/list (Microsoft.Resources/resourceGroups/write).
-
Create a clone.
output_string=$(docker run --rm servicebus-cloner:latest \ --tenant=a2c511af-be9b-4d4f-a265-d2a3fcf3dc98 \ --subscription=89d5e09c-47ac-4008-8b09-3f6e67c682eb \ --clientid=5bc23718-68c1-472c-9a82-6c73f48d049d \ --clientsecret=MySuperSecret \ --sbFrom=MyRealServiceBusName \ --sbTo=MyTemporaryServiceBusForTesting)
-
Run your tests
dotnet test -e "ServiceBusConnectionString=$output_string"
-
Clean up resources
docker run --rm servicebus-cloner:latest \ --tenant=a2c511af-be9b-4d4f-a265-d2a3fcf3dc98 \ --subscription=89d5e09c-47ac-4008-8b09-3f6e67c682eb \ --clientid=5bc23718-68c1-472c-9a82-6c73f48d049d \ --clientsecret=MySuperSecret \ --sbTo=MyTemporaryServiceBusNameForTesting \ --action=delete
For some use cases, like docker-compose,it can be benificial to use the ephemeral flag. The test service will exist while the container runs. It is deleted on container SIGTERM. Use a volume to fetch the created connectionstring from the container.
docker run -v "mypath:/app/out"
--rm servicebus-cloner:latest \
--out=/app/out/connectionstring \
--tenant=a2c511af-be9b-4d4f-a265-d2a3fcf3dc98 \
--subscription=89d5e09c-47ac-4008-8b09-3f6e67c682eb \
--clientid=5bc23718-68c1-472c-9a82-6c73f48d049d \
--clientsecret=MySuperSecret \
--sbFrom=MyRealServiceBusName \
--sbTo=MyTemporaryServiceBusForTesting \
--action=ephemeral