Using Azure Service Bus Emulator as a Test Container

This sample project shows how to use the Azure Service Bus emulator as a test container for local development and integration testing.

The Service Bus emulator, like the Event Hubs emulator, doesn’t have a dedicated Testcontainers module and relies on Azure SQL Edge.

You can initialize the Service Bus emulator as a test container in two ways:

1️⃣ Code Compose: Setting up containers programmatically with the GenericContainer class.
2️⃣ Docker Compose: Using a Docker Compose file for container orchestration.

For more details, visit the GitHub repository: https://github.com/mirkoiv/servicebus-emulator-as-testcontainer

Building Service Bus emulator as a Test Container

Service Bus emulator does not have a Testcontainers module (yet), and additionally the emulator requires Azure SQL Edge.

There are two ways to initialize the Service Bus Emulator as a test container:

1️⃣ code compose – Composing through code using the GenericContainer class – AbstractServiceBusContainerCodeCompose
2️⃣ docker compose – Using a Docker Compose file and ComposeContainer class – AbstractServiceBusContainerDockerCompose

Key Differences Between the Two Approaches

In the first case, tests or applications interact directly with the ports exposed by the generic emulator and storage test containers. In the second case, an additional ambassador container is created, serving as a proxy to the generic emulator and storage containers.

Code Compose:

Docker Compose:

For more details and run samples, visit the GitHub repository: https://github.com/mirkoiv/servicebus-emulator-as-testcontainer

Using Azure Event Hubs Emulator as a Test Container

This sample project demonstrates how to utilize the Azure Event Hubs emulator as a test container for local development and integration testing.

The Event Hubs emulator does not have a Testcontainers module and depends on the Azure Storage emulator (Azurite).

There are two ways to initialize the Event Hub Emulator as a test container:

1️⃣ Code Compose: Setting up containers programmatically with the GenericContainer class.
2️⃣ Docker Compose: Using a Docker Compose file for container orchestration.

For more details, visit the GitHub repository: https://github.com/mirkoiv/event-hubs-emulator-as-testcontainer

Building Event Hubs emulator as Test Container

Event Hubs emulator does not have a Testcontainers module (yet), and additionally the emulator requires Azure Storage emulator (azurite).

There are two ways to initialize the Event Hub Emulator as a test container:

1️⃣ code compose – Composing through code using the GenericContainer class – AbstractEventHubContainerCodeCompose
2️⃣ docker compose – Using a Docker Compose file and ComposeContainer class – AbstractEventHubContainerDockerCompose

Key Differences Between the Two Approaches

In the first case, tests or applications interact directly with the ports exposed by the generic emulator and storage test containers. In the second case, an additional ambassador container is created, serving as a proxy to the generic emulator and storage containers.

Code Compose:

eventhubs emulator - code compose

Docker Compose:

eventhubs emulator - docker compose

Using Spring Cloud Azure with Event Hubs Emulator – Workaround

Microsoft recently released the Azure Event Hubs emulator, which could simplify local development and testing.

Unfortunately, at the moment, the Azure Event Hubs emulator cannot be directly used with Spring Azure Cloud 4.x/5.x. This is because the Azure SDK for Java does not support the new connection string parameter ‘UseDevelopmentEmulator’ and cannot connect to the unsecured AMQP port.

However, there is a workaround solution available.

Feel free to explore examples and the workaround solution at https://github.com/mirkoiv/azure-event-hubs-emulator-installer

Problem

The emulator runs on the unsecured AMQP 5672 port. To interact with the emulator, you need to use a predefined connection string that includes the new parameter ‘UseDevelopmentEmulator’.

This new parameter is utilized within the Azure SDK to establish a connection to the emulator over port 5672. Otherwise, the connection will default to the secured AMQP port 5671, requiring a certificate for authentication.

Spring Azure Cloud versions 4.x/5.x depend on an SDK that does not support the new connection string parameter. This results in an ‘Illegal connection string parameter name: UseDevelopmentEmulator’ exception.

You can attempt to use a newer version of the SDK dependency (azure-core-amqp 2.9.4), which does support the new parameter. However, be aware that it also contains a bug (Azure/azure-sdk-for-java#40938) preventing the setup of an insecure connection to the emulator.

Workaround

A workaround solution involves using a self-signed certificate and a reverse proxy with SSL termination in front of the emulator.

For details visit https://github.com/mirkoiv/azure-event-hubs-emulator-installer/blob/main/Sample-Code-Snippets/Java/spring-cloud-azure-samples/README.md