Skip to content

Commit

Permalink
Registry Service Bus conn string provider only when conn string is no…
Browse files Browse the repository at this point in the history
…t empty (#43076)
  • Loading branch information
moarychan authored Nov 25, 2024
1 parent e9953c1 commit cac37f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sdk/spring/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ This section includes changes in `spring-cloud-azure-autoconfigure` module.

#### Features Added
- Support customize StaticConnectionStringProvider<AzureServiceType.EventHubs> bean. [#42919](https://github.com/Azure/azure-sdk-for-java/pull/42919).
- Support customize StaticConnectionStringProvider<AzureServiceType.ServiceBus> bean. [#43076](https://github.com/Azure/azure-sdk-for-java/pull/43076).

#### Bugs Fixed
- Fix error: Event Hubs connection string is still used when it's configured to empty string. [#42880](https://github.com/Azure/azure-sdk-for-java/issues/42880).
- Fix error: Service Bus connection string is still used when it's configured to empty string. [#42880](https://github.com/Azure/azure-sdk-for-java/issues/42880).

### Spring Integration Azure Core
This section includes changes in the `spring-integration-azure-core` module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import com.azure.spring.cloud.service.implementation.servicebus.factory.ServiceBusClientBuilderFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Expand Down Expand Up @@ -51,7 +51,8 @@ ServiceBusClientBuilder serviceBusClientBuilder(ServiceBusClientBuilderFactory f
}

@Bean
@ConditionalOnProperty("spring.cloud.azure.servicebus.connection-string")
@ConditionalOnExpression("'${spring.cloud.azure.servicebus.connection-string:}' != ''")
@ConditionalOnMissingBean(value = AzureServiceType.ServiceBus.class, parameterizedContainer = ServiceConnectionStringProvider.class)
StaticConnectionStringProvider<AzureServiceType.ServiceBus> staticServiceBusConnectionStringProvider() {

return new StaticConnectionStringProvider<>(AzureServiceType.SERVICE_BUS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.azure.data.appconfiguration.ConfigurationClientBuilder;
import com.azure.messaging.servicebus.ServiceBusClientBuilder;
import com.azure.spring.cloud.autoconfigure.implementation.TestBuilderCustomizer;
import com.azure.spring.cloud.autoconfigure.implementation.context.properties.AzureGlobalProperties;
import com.azure.spring.cloud.autoconfigure.implementation.servicebus.properties.AzureServiceBusProperties;
import com.azure.spring.cloud.core.provider.connectionstring.StaticConnectionStringProvider;
import com.azure.spring.cloud.core.service.AzureServiceType;
import com.azure.spring.cloud.service.implementation.servicebus.factory.ServiceBusClientBuilderFactory;
Expand Down Expand Up @@ -77,6 +79,19 @@ void otherCustomizerShouldNotBeCalled() {
});
}

@Test
void configureWithNamespaceAndEmptyConnectionString() {
this.contextRunner.withConfiguration(AutoConfigurations.of(AzureServiceBusAutoConfiguration.class))
.withPropertyValues(
"spring.cloud.azure.servicebus.connection-string=",
"spring.cloud.azure.servicebus.namespace=test-servicebus-namespace")
.withBean(AzureGlobalProperties.class, AzureGlobalProperties::new)
.run(context -> {
assertThat(context).hasSingleBean(AzureServiceBusProperties.class);
assertThat(context).doesNotHaveBean(StaticConnectionStringProvider.class);
});
}

private static class ServiceBusBuilderCustomizer extends TestBuilderCustomizer<ServiceBusClientBuilder> {

}
Expand Down

0 comments on commit cac37f7

Please sign in to comment.