Add ConnectionDetails support for EventHubs#47926
Conversation
…ners, and docker-compose Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
Co-authored-by: rujche <171773178+rujche@users.noreply.github.com>
API Change CheckAPIView identified API level changes in this PR and created the following API reviews com.azure.spring:spring-cloud-azure-docker-compose |
There was a problem hiding this comment.
Pull request overview
This PR implements Spring Boot ConnectionDetails abstraction for EventHubs, following the established pattern from ServiceBus, Cosmos DB, and Storage services. It enables seamless integration with Testcontainers and Docker Compose for EventHubs emulator auto-configuration.
Changes:
- Added ConnectionDetails infrastructure in the autoconfigure module with conditional configuration beans
- Implemented Testcontainers factory for EventHubsEmulatorContainer integration with test coverage
- Implemented Docker Compose factory for eventhubs-emulator service detection with test coverage
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsConnectionDetails.java |
Interface defining connection string abstraction for EventHubs ConnectionDetails |
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/AzureEventHubsPropertiesConfiguration.java |
Configuration class orchestrating conditional property bean creation |
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/ConfigurationWithConnectionDetailsBean.java |
Conditional bean configuration when ConnectionDetails is available |
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/properties/ConfigurationWithoutConnectionDetailsBean.java |
Fallback bean configuration when ConnectionDetails is not available (missing conditional on enabled flag) |
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/AzureEventHubsAutoConfiguration.java |
Refactored to delegate property configuration to new properties configuration classes |
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/CustomAzureEventHubsConnectionDetails.java |
Test implementation of ConnectionDetails for validation |
sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/eventhubs/AzureEventHubsAutoConfigurationTests.java |
Added test to verify ConnectionDetails takes precedence over properties |
sdk/spring/spring-cloud-azure-testcontainers/src/main/java/com/azure/spring/cloud/testcontainers/implementation/service/connection/eventhubs/EventHubsContainerConnectionDetailsFactory.java |
Factory for creating ConnectionDetails from EventHubsEmulatorContainer |
sdk/spring/spring-cloud-azure-testcontainers/src/main/resources/META-INF/spring.factories |
Registered EventHubs container factory for service connection discovery |
sdk/spring/spring-cloud-azure-testcontainers/src/test/java/com/azure/spring/cloud/testcontainers/implementation/service/connection/eventhubs/EventHubsContainerConnectionDetailsFactoryTests.java |
Integration test validating Testcontainers auto-configuration |
sdk/spring/spring-cloud-azure-testcontainers/src/test/resources/eventhubs/Config.json |
EventHubs emulator configuration for tests |
sdk/spring/spring-cloud-azure-testcontainers/pom.xml |
Added optional dependency on azure-messaging-eventhubs |
sdk/spring/spring-cloud-azure-docker-compose/src/main/java/com/azure/spring/cloud/docker/compose/implementation/service/connection/eventhubs/EventHubsDockerComposeConnectionDetailsFactory.java |
Factory for creating ConnectionDetails from Docker Compose service |
sdk/spring/spring-cloud-azure-docker-compose/src/main/resources/META-INF/spring.factories |
Registered EventHubs Docker Compose factory for service connection discovery |
sdk/spring/spring-cloud-azure-docker-compose/src/test/java/com/azure/spring/cloud/docker/compose/implementation/service/connection/eventhubs/EventHubsDockerComposeConnectionDetailsFactoryTests.java |
Integration test validating Docker Compose auto-configuration |
sdk/spring/spring-cloud-azure-docker-compose/src/test/resources/com/azure/spring/cloud/docker/compose/implementation/service/connection/eventhubs/eventhubs-compose.yaml |
Docker Compose configuration for tests |
sdk/spring/spring-cloud-azure-docker-compose/src/test/resources/com/azure/spring/cloud/docker/compose/implementation/service/connection/eventhubs/Config.json |
EventHubs emulator configuration for Docker Compose tests |
sdk/spring/spring-cloud-azure-docker-compose/pom.xml |
Added optional dependency on azure-messaging-eventhubs |
...configure/implementation/eventhubs/properties/ConfigurationWithoutConnectionDetailsBean.java
Show resolved
Hide resolved
EventHubsDockerComposeConnectionDetailsFactoryTests passed in wsl nowHere is the log: rujche@RujcheThinkPad:~/work/git-repositories/main/azure-sdk-for-java$ git pull
remote: Enumerating objects: 48, done.
remote: Counting objects: 100% (32/32), done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 48 (delta 5), reused 19 (delta 5), pack-reused 16 (from 2)
Unpacking objects: 100% (48/48), 34.58 KiB | 823.00 KiB/s, done.
From https://github.com/Azure/azure-sdk-for-java
7fc8e138dfa..40bf4bb23e1 copilot/add-support-connectiondetails -> origin/copilot/add-support-connectiondetails
5fbf70da6c5..cee16633f4d main -> origin/main
Updating 7fc8e138dfa..40bf4bb23e1
Fast-forward
.../src/test/resources/com/azure/spring/cloud/docker/compose/implementation/service/connection/eventhubs/eventhubs-compose.yaml | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
rujche@RujcheThinkPad:~/work/git-repositories/main/azure-sdk-for-java$ mvn -Dmaven.repo.local=/mnt/c/Users/rujche/.m2/repository -pl sdk/spring/spring-cloud-azure-docker-compose -Dtest=EventHubsDockerComposeConnectionDetailsFactoryTests,ServiceBusDockerComposeConnectionDetailsFactoryTests -DfailIfNoTests=false test
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.azure.spring:spring-cloud-azure-docker-compose >---------
[INFO] Building Spring Cloud Azure Docker Compose 7.1.0-beta.1
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- enforcer:3.6.2:enforce (default-cli) @ spring-cloud-azure-docker-compose ---
[INFO] Rule 0: org.apache.maven.enforcer.rules.dependency.BannedDependencies passed
[INFO] Rule 1: org.apache.maven.enforcer.rules.dependency.RequireReleaseDeps passed
[INFO]
[INFO] --- codesnippet:1.0.0-beta.10:update-codesnippet (update-codesnippets) @ spring-cloud-azure-docker-compose ---
[INFO]
[INFO] --- spotless:2.30.0:apply (spotless-apply) @ spring-cloud-azure-docker-compose ---
[INFO] Spotless apply skipped
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ spring-cloud-azure-docker-compose ---
[INFO] Copying 0 resource from src/main/resources to target/classes
[INFO] Copying 1 resource from src/main/resources to target/classes
[INFO]
[INFO] --- compiler:3.14.1:compile (default-compile) @ spring-cloud-azure-docker-compose ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- compiler:3.14.1:compile (default) @ spring-cloud-azure-docker-compose ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- build-helper:3.6.1:add-test-source (compile-samples-source) @ spring-cloud-azure-docker-compose ---
[INFO] Test Source directory: /home/rujche/work/git-repositories/main/azure-sdk-for-java/sdk/spring/spring-cloud-azure-docker-compose/src/samples/java added.
[INFO]
[INFO] --- build-helper:3.6.1:add-test-resource (add-properties-to-test) @ spring-cloud-azure-docker-compose ---
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ spring-cloud-azure-docker-compose ---
[INFO] Copying 5 resources from src/test/resources to target/test-classes
[INFO] Copying 0 resource from src/main/resources to target/test-classes
[INFO]
[INFO] --- compiler:3.14.1:testCompile (default-testCompile) @ spring-cloud-azure-docker-compose ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- jacoco:0.8.14:prepare-agent (prepare-agent) @ spring-cloud-azure-docker-compose ---
[INFO] Skipping JaCoCo execution because property jacoco.skip is set.
[INFO]
[INFO] --- surefire:3.5.3:test (default-test) @ spring-cloud-azure-docker-compose ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
WARNING: Unknown module: com.azure.core specified to --add-opens
[INFO] Running com.azure.spring.cloud.docker.compose.implementation.service.connection.eventhubs.EventHubsDockerComposeConnectionDetailsFactoryTests
[INFO] Running com.azure.spring.cloud.docker.compose.implementation.service.connection.bus.ServiceBusDockerComposeConnectionDetailsFactoryTests
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.0.2)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v4.0.2)
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 242.2 s -- in com.azure.spring.cloud.docker.compose.implementation.service.connection.eventhubs.EventHubsDockerComposeConnectionDetailsFactoryTests
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 247.1 s -- in com.azure.spring.cloud.docker.compose.implementation.service.connection.bus.ServiceBusDockerComposeConnectionDetailsFactoryTests
[ERROR] Surefire is going to kill self fork JVM. The exit has elapsed 30 seconds after System.exit(0).
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 3, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:22 min
[INFO] Finished at: 2026-02-09T13:13:23+08:00
[INFO] ------------------------------------------------------------------------
rujche@RujcheThinkPad:~/work/git-repositories/main/azure-sdk-for-java$ |
...e/spring/cloud/autoconfigure/implementation/servicebus/AzureServiceBusAutoConfiguration.java
Show resolved
Hide resolved
...g/cloud/autoconfigure/implementation/eventhubs/AzureEventHubsClientBuilderConfiguration.java
Show resolved
Hide resolved
|
/azp run java - spring - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/check-enforcer override |
|
Ignore the failures in Will fix the failure in another PR. |
(cherry picked from commit ba63ffc)

This pull request refactors the Event Hubs and Cosmos auto-configuration in the Spring Cloud Azure SDK to simplify configuration, improve modularity, and enable support for connection details beans. The changes remove legacy base classes and property-loading logic, introduce new configuration classes, and update conditional annotations to ensure beans are only created when appropriate properties or beans are present.
Event Hubs auto-configuration refactoring:
AzureServiceConfigurationBaseand manual property loading inAzureEventHubsAutoConfiguration, now relying onAzureEventHubsPropertiesConfigurationfor property setup.AzureEventHubsPropertiesConfigurationto handle property beans and support both connection string and connection details beans.AzureEventHubsClientBuilderConfigurationto importAzureEventHubsPropertiesConfiguration, requireAzureEventHubsPropertiesbean, and add support forAzureEventHubsConnectionDetailsbeans. [1] [2]AzureEventHubsConnectionDetailsfor connection details beans, enabling more flexible connection configuration.Conditional bean creation improvements:
@ConditionalOnAnyPropertyannotations with@ConditionalOnBean(AzureEventHubsProperties.class)in Event Hubs-related configuration classes to ensure beans are only created when relevant properties are present. [1] [2] [3] [4] [5]Cosmos auto-configuration simplification:
AzureServiceConfigurationBaseand property-loading logic inAzureCosmosAutoConfiguration, simplifying the class.Cleanup and removal of legacy code:
These changes make the auto-configuration more modular, easier to maintain, and compatible with Spring Boot's connection details abstraction.