[Spring] Make ServiceBus JMS connection factory creation customizable#49676
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a Spring Boot extension point that lets applications customize how ServiceBusJmsConnectionFactory instances are created (including using custom subclasses), and wires that extension point through the Service Bus JMS auto-configuration with updated test coverage.
Changes:
- Introduces a new public functional interface,
AzureServiceBusJmsConnectionFactoryFactory, for pluggableServiceBusJmsConnectionFactorycreation. - Adds a default
@ConditionalOnMissingBeanimplementation of the factory inServiceBusJmsAutoConfigurationand updates internal wiring to obtain and use the factory bean. - Expands tests to cover custom factory creation across direct, caching, pooling, and passwordless scenarios; updates
sdk/spring/CHANGELOG.md.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfigurationTests.java | Adds tests and a custom subclass + factory bean to validate the new customization hook across scenarios. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/jms/AzureServiceBusJmsConnectionFactoryFactory.java | New public extension interface for user-provided connection factory creation. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryFactory.java | Refactors internal factory creation to use the new instance-factory extension point. |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsConnectionFactoryConfiguration.java | Updates auto-configured sender ConnectionFactory registration to obtain and use the factory bean (while retaining a static helper). |
| sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsAutoConfiguration.java | Adds a default AzureServiceBusJmsConnectionFactoryFactory bean when one is not supplied by the application. |
| sdk/spring/CHANGELOG.md | Documents the newly added extension point in the top-level Spring changelog. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/implementation/jms/ServiceBusJmsContainerConfiguration.java:76
- There is trailing whitespace on the blank line between field declarations and the following comment. This can trip whitespace/style checks and creates noisy diffs. Please remove the whitespace so the line is truly empty.
private final JmsProperties jmsProperties;
// Memoized dedicated listener container ConnectionFactory instances to avoid duplicates and enable lifecycle management
|
/azp run java - spring - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…ed-subclass-of-ServiceBusJmsConnectionFactory-into-the-configuration
| } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { | ||
| throw new IllegalStateException("Unable to create JmsConnectionFactory", ex); | ||
| } | ||
| private ServiceBusJmsConnectionFactory createConnectionFactoryInstance( |
There was a problem hiding this comment.
I prefer to keep this logic here because the responsibility of the configuration class is simply to create beans, and it doesn't need much other logic. This class is similar to the class in the package path com.azure.spring.cloud.service.implementation.xxx.factory, both are responsible for credential logic, but the difference is that it is stored in the autoconfiguration module.
| * </p> | ||
| */ | ||
| @FunctionalInterface | ||
| public interface AzureServiceBusJmsConnectionFactoryFactory { |
There was a problem hiding this comment.
I'm a bit confused about the naming of the dual-factory pattern because there's already a class with the same name suffix, com.azure.spring.cloud.autoconfigure.implementation.jms.ServiceBusJmsConnectionFactoryFactory, but it's an internally used class. Could you change its name to end with "provider" or "supplier"? It would be more developer-friendly.
Description
This PR implements the feature request from #45942 by adopting the old PR #46052 approach for connection-factory creation customization.
What changed
AzureServiceBusJmsConnectionFactoryFactoryas a public extension interface.@ConditionalOnMissingBeanimplementation in Service Bus JMS auto-configuration.ServiceBusJmsConnectionFactoryFactoryto use the new extension interface.ServiceBusJmsConnectionFactoryConfigurationto obtain and use the factory bean.ServiceBusJmsContainerConfigurationto also use the same factory bean extension point, so listener-container paths honor custom factories too.TokenCredentialProvideronce at bean creation time and reusing it for factory invocations.sdk/spring/CHANGELOG.md(with PR reference).Old PR comment resolution
AzureServiceBusJmsConnectionFactoryFactory).Verification
mvn -pl sdk/spring/spring-cloud-azure-autoconfigure -Dtest=ServiceBusJmsConnectionFactoryConfigurationTests test -DskipITs -Dspotbugs.skip=true -Dcheckstyle.skip=truemvn -pl sdk/spring/spring-cloud-azure-autoconfigure -DskipTests checkstyle:checkFixes #45942