Skip to content

fix(ServiceBus): Replace amqp protocol by sb for connection string#1675

Merged
HofmeisterAn merged 1 commit intotestcontainers:developfrom
Greybird:service-bus-protocol
Apr 1, 2026
Merged

fix(ServiceBus): Replace amqp protocol by sb for connection string#1675
HofmeisterAn merged 1 commit intotestcontainers:developfrom
Greybird:service-bus-protocol

Conversation

@Greybird
Copy link
Copy Markdown
Contributor

@Greybird Greybird commented Apr 1, 2026

What does this PR do?

This PR fixes the incorrect amqp protocol used in the connection string for Azure Service Bus, to replace it with the expected sb protocol.

Why is it important?

  1. The emulator documentation uses the sb protocol: choosing-the-right-connection-string,
  2. The Java implementation of the module uses the sb protocol,
  3. The Go implemenation of the module uses the sb protocol,
  4. On Azure, connection strings for sb and amqp protocol vary largely:
    • sb: Endpoint=sb://<namespace>/;SharedAccessKeyName=<keyname>;SharedAccessKey=<key>
    • amqp: amqps://<keyname>:<key>@<namespace>.servicebus.windows.net:5671/?verify=verify_none
    • connectring string returned by the module is clearly in the sb form: Endpoint=amqp://127.0.0.1:33036/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true
  5. MassTransit library fails to interact withe the emulator when provided the amqp connection string returned by the module. Replacing amqp by sb in the connection string allows it to behave correctly (cc @phatboyg)

Related issues

  • would be glad to open one should you think this is necessary for such a small change.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the endpoint URI scheme in Azure Service Bus connection strings for improved compatibility and correct protocol handling.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 1, 2026

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit f3e5318
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/69ccb8c95ac1d000082bcf1b
😎 Deploy Preview https://deploy-preview-1675--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Walkthrough

ServiceBusContainer.GetConnectionString() now constructs the Endpoint URI using the sb scheme instead of the amqp scheme when building the returned semicolon-separated connection string.

Changes

Cohort / File(s) Summary
ServiceBusContainer Connection String
src/Testcontainers.ServiceBus/ServiceBusContainer.cs
Modified GetConnectionString() to use the "sb" URI scheme instead of "amqp" when constructing the Endpoint property in the connection string.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • HofmeisterAn

Poem

🐰 A switch from amqp to sb so fine,
The connection string now will align,
One little change, but mighty in effect,
ServiceBus connections are now correct! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description includes comprehensive information: what changed, detailed rationale with references to emulator docs and other implementations, and evidence of real-world issues (MassTransit compatibility).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing the amqp protocol with sb in the Azure Service Bus connection string.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/Testcontainers.ServiceBus/ServiceBusContainer.cs (1)

20-45: Consider extracting shared connection string logic to reduce duplication.

Both GetConnectionString() and GetHttpConnectionString() share identical logic except for the port number. You could extract a private helper method:

♻️ Suggested refactor
 public string GetConnectionString()
 {
-    var properties = new Dictionary<string, string>();
-    properties.Add("Endpoint", new UriBuilder("sb", Hostname, GetMappedPublicPort(ServiceBusBuilder.ServiceBusPort)).ToString());
-    properties.Add("SharedAccessKeyName", "RootManageSharedAccessKey");
-    properties.Add("SharedAccessKey", "SAS_KEY_VALUE");
-    properties.Add("UseDevelopmentEmulator", "true");
-    return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value)));
+    return BuildConnectionString(ServiceBusBuilder.ServiceBusPort);
 }

 public string GetHttpConnectionString()
 {
-    var properties = new Dictionary<string, string>();
-    properties.Add("Endpoint", new UriBuilder("sb", Hostname, GetMappedPublicPort(ServiceBusBuilder.ServiceBusHttpPort)).ToString());
-    properties.Add("SharedAccessKeyName", "RootManageSharedAccessKey");
-    properties.Add("SharedAccessKey", "SAS_KEY_VALUE");
-    properties.Add("UseDevelopmentEmulator", "true");
-    return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value)));
+    return BuildConnectionString(ServiceBusBuilder.ServiceBusHttpPort);
 }
+
+private string BuildConnectionString(ushort port)
+{
+    var properties = new Dictionary<string, string>
+    {
+        { "Endpoint", new UriBuilder("sb", Hostname, GetMappedPublicPort(port)).ToString() },
+        { "SharedAccessKeyName", "RootManageSharedAccessKey" },
+        { "SharedAccessKey", "SAS_KEY_VALUE" },
+        { "UseDevelopmentEmulator", "true" }
+    };
+    return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value)));
+}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Testcontainers.ServiceBus/ServiceBusContainer.cs` around lines 20 - 45,
Both GetConnectionString and GetHttpConnectionString duplicate the same
dictionary-building and join logic; extract that into a private helper (e.g.,
BuildConnectionString) that takes the varying port (use
ServiceBusBuilder.ServiceBusPort and ServiceBusBuilder.ServiceBusHttpPort) and
returns the joined string. Replace GetConnectionString and
GetHttpConnectionString to call this helper with the appropriate port (and keep
the same keys
"Endpoint","SharedAccessKeyName","SharedAccessKey","UseDevelopmentEmulator"), so
only the port differs and duplication is removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/Testcontainers.ServiceBus/ServiceBusContainer.cs`:
- Around line 20-45: Both GetConnectionString and GetHttpConnectionString
duplicate the same dictionary-building and join logic; extract that into a
private helper (e.g., BuildConnectionString) that takes the varying port (use
ServiceBusBuilder.ServiceBusPort and ServiceBusBuilder.ServiceBusHttpPort) and
returns the joined string. Replace GetConnectionString and
GetHttpConnectionString to call this helper with the appropriate port (and keep
the same keys
"Endpoint","SharedAccessKeyName","SharedAccessKey","UseDevelopmentEmulator"), so
only the port differs and duplication is removed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3c25386e-6cbc-4b34-abfb-c21625efbc0e

📥 Commits

Reviewing files that changed from the base of the PR and between 19ba742 and f3e5318.

📒 Files selected for processing (1)
  • src/Testcontainers.ServiceBus/ServiceBusContainer.cs

Copy link
Copy Markdown
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@HofmeisterAn HofmeisterAn changed the title fix(servicebus): Replace amqp protocol by sb for connection string fix(ServiceBus): Replace amqp protocol by sb for connection string Apr 1, 2026
@HofmeisterAn HofmeisterAn merged commit 3d42f9b into testcontainers:develop Apr 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants