Skip to content

Commit

Permalink
Spring integration and Spring Cloud Stream upgrade Service Bus SDK to…
Browse files Browse the repository at this point in the history
… Track2 (#20251)

Co-authored-by: Michael Qi <v-michaelqi@microsoft.com>
Co-authored-by: Xiaolu Dai <xiada@microsoft.com>
  • Loading branch information
3 people authored May 14, 2021
1 parent 642b1db commit 2466b8b
Show file tree
Hide file tree
Showing 83 changed files with 1,960 additions and 1,905 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,15 @@
<Bug pattern="NM_METHOD_NAMING_CONVENTION"/>
</Match>

<Match>
<Bug pattern="UWF_NULL_FIELD"/>
<Class name="com.azure.spring.integration.core.AbstractInboundChannelAdapter"/>
<Or>
<Field name="subscribeByGroupOperation"/>
<Field name="subscribeOperation"/>
</Or>
</Match>

<Match>
<Class name="com.azure.spring.messaging.config.AzureListenerEndpointRegistrar"/>
<Bug pattern="NP_NULL_ON_SOME_PATH"/>
Expand Down
6 changes: 3 additions & 3 deletions sdk/spring/azure-spring-cloud-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version> <!-- {x-version-update;junit:junit;external_dependency} -->
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.vintage:junit-vintage-engine;external_dependency} -->
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

package com.azure.spring.cloud.autoconfigure.servicebus;

import com.azure.messaging.servicebus.ServiceBusReceivedMessage;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.cloud.autoconfigure.context.AzureContextAutoConfiguration;
import com.azure.spring.cloud.context.core.config.AzureProperties;
import com.azure.spring.cloud.context.core.impl.ServiceBusNamespaceManager;
import com.azure.spring.cloud.telemetry.TelemetryCollector;
import com.azure.spring.integration.servicebus.factory.ServiceBusConnectionStringProvider;
import com.microsoft.azure.servicebus.IMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -32,7 +32,7 @@
*/
@Configuration
@AutoConfigureAfter(AzureContextAutoConfiguration.class)
@ConditionalOnClass(IMessage.class)
@ConditionalOnClass(ServiceBusReceivedMessage.class)
@ConditionalOnProperty(value = "spring.cloud.azure.servicebus.enabled", matchIfMissing = true)
@EnableConfigurationProperties(AzureServiceBusProperties.class)
public class AzureServiceBusAutoConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.servicebus;

import com.azure.messaging.servicebus.ServiceBusProcessorClient;
import com.azure.spring.cloud.context.core.config.AzureProperties;
import com.azure.spring.cloud.context.core.impl.ServiceBusNamespaceManager;
import com.azure.spring.cloud.context.core.impl.ServiceBusQueueManager;
Expand All @@ -13,7 +14,6 @@
import com.azure.spring.integration.servicebus.factory.ServiceBusQueueClientFactory;
import com.azure.spring.integration.servicebus.queue.ServiceBusQueueOperation;
import com.azure.spring.integration.servicebus.queue.ServiceBusQueueTemplate;
import com.microsoft.azure.servicebus.QueueClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -37,7 +37,7 @@
*/
@Configuration
@AutoConfigureAfter(AzureServiceBusAutoConfiguration.class)
@ConditionalOnClass(value = { QueueClient.class, ServiceBusQueueClientFactory.class })
@ConditionalOnClass(value = { ServiceBusProcessorClient.class, ServiceBusQueueClientFactory.class })
@ConditionalOnProperty(value = "spring.cloud.azure.servicebus.enabled", matchIfMissing = true)
public class AzureServiceBusQueueAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.servicebus;

import com.azure.messaging.servicebus.ServiceBusProcessorClient;
import com.azure.spring.cloud.context.core.config.AzureProperties;
import com.azure.spring.cloud.context.core.impl.ServiceBusNamespaceManager;
import com.azure.spring.cloud.context.core.impl.ServiceBusTopicManager;
Expand All @@ -14,7 +15,6 @@
import com.azure.spring.integration.servicebus.factory.ServiceBusTopicClientFactory;
import com.azure.spring.integration.servicebus.topic.ServiceBusTopicOperation;
import com.azure.spring.integration.servicebus.topic.ServiceBusTopicTemplate;
import com.microsoft.azure.servicebus.TopicClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -38,7 +38,7 @@
*/
@Configuration
@AutoConfigureAfter(AzureServiceBusAutoConfiguration.class)
@ConditionalOnClass(TopicClient.class)
@ConditionalOnClass(value = {ServiceBusProcessorClient.class, ServiceBusTopicClientFactory.class})
@ConditionalOnProperty(value = "spring.cloud.azure.servicebus.enabled", matchIfMissing = true)
public class AzureServiceBusTopicAutoConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

package com.azure.spring.cloud.autoconfigure.servicebus;

import com.azure.messaging.servicebus.ServiceBusReceivedMessage;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.cloud.context.core.config.AzureProperties;
import com.azure.spring.cloud.context.core.impl.ServiceBusNamespaceManager;
import com.azure.spring.integration.servicebus.factory.ServiceBusConnectionStringProvider;
import com.microsoft.azure.servicebus.IMessage;
import org.junit.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
Expand Down Expand Up @@ -59,13 +59,13 @@ public void testWithoutAzureResourceManagerProvided() {

@Test
public void testWithoutServiceBusSDKInClasspath() {
this.contextRunner.withClassLoader(new FilteredClassLoader(IMessage.class))
this.contextRunner.withClassLoader(new FilteredClassLoader(ServiceBusReceivedMessage.class))
.run(context -> assertThat(context).doesNotHaveBean(AzureServiceBusProperties.class));
}

@Test(expected = NoSuchBeanDefinitionException.class)
public void testAzureServiceBusPropertiesValidation() {
this.contextRunner.withClassLoader(new FilteredClassLoader(IMessage.class))
this.contextRunner.withClassLoader(new FilteredClassLoader(ServiceBusReceivedMessage.class))
.run(context -> context.getBean(AzureServiceBusProperties.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.servicebus;

import com.azure.messaging.servicebus.ServiceBusProcessorClient;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.cloud.context.core.config.AzureProperties;
import com.azure.spring.cloud.context.core.impl.ServiceBusNamespaceManager;
Expand All @@ -12,7 +13,6 @@
import com.azure.spring.integration.servicebus.factory.ServiceBusQueueClientFactory;
import com.azure.spring.integration.servicebus.queue.ServiceBusQueueOperation;
import com.azure.spring.integration.servicebus.queue.ServiceBusQueueTemplate;
import com.microsoft.azure.servicebus.QueueClient;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -21,6 +21,10 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
Expand All @@ -30,6 +34,24 @@ public class AzureServiceBusQueueAutoConfigurationTest {
private static final String SERVICE_BUS_PROPERTY_PREFIX = "spring.cloud.azure.servicebus.";
private static final String AZURE_PROPERTY_PREFIX = "spring.cloud.azure.";

private static final String NAMESPACE_NAME = "dummyNamespaceName";
private static final String DEFAULT_DOMAIN_NAME = "servicebus.windows.net/";
private static final String ENDPOINT_FORMAT = "sb://%s.%s";
private static final String SHARED_ACCESS_KEY_NAME = "dummySasKeyName";
private static final String SHARED_ACCESS_KEY = "dummySasKey";
private static final String ENDPOINT = getUri(ENDPOINT_FORMAT, NAMESPACE_NAME, DEFAULT_DOMAIN_NAME).toString();
static final String NAMESPACE_CONNECTION_STRING = String.format("Endpoint=%s;SharedAccessKeyName=%s;SharedAccessKey=%s",
ENDPOINT, SHARED_ACCESS_KEY_NAME, SHARED_ACCESS_KEY);

private static URI getUri(String endpointFormat, String namespace, String domainName) {
try {
return new URI(String.format(Locale.US, endpointFormat, namespace, domainName));
} catch (URISyntaxException exception) {
throw new IllegalArgumentException(String.format(Locale.US,
"Invalid namespace name: %s", namespace), exception);
}
}

private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AzureServiceBusQueueAutoConfiguration.class));

Expand All @@ -41,7 +63,7 @@ public void testAzureServiceBusDisabled() {

@Test
public void testWithoutAzureServiceBusQueueClient() {
this.contextRunner.withClassLoader(new FilteredClassLoader(QueueClient.class))
this.contextRunner.withClassLoader(new FilteredClassLoader(ServiceBusProcessorClient.class))
.run(context -> assertThat(context).doesNotHaveBean(ServiceBusQueueOperation.class));
}

Expand All @@ -61,17 +83,17 @@ public void testWithServiceBusNamespaceManager() {
public void testQueueClientFactoryCreated() {
this.contextRunner.withUserConfiguration(AzureServiceBusAutoConfiguration.class,
TestConfigWithServiceBusNamespaceManager.class)
.withPropertyValues(SERVICE_BUS_PROPERTY_PREFIX + "connection-string=str1")
.withPropertyValues(SERVICE_BUS_PROPERTY_PREFIX + "connection-string=" + NAMESPACE_CONNECTION_STRING)
.run(context -> assertThat(context).hasSingleBean(ServiceBusQueueClientFactory.class)
.hasSingleBean(ServiceBusQueueOperation.class));
}

@Test
public void testConnectionStringProvided() {
this.contextRunner.withPropertyValues(SERVICE_BUS_PROPERTY_PREFIX + "connection-string=str1")
this.contextRunner.withPropertyValues(SERVICE_BUS_PROPERTY_PREFIX + "connection-string=" + NAMESPACE_CONNECTION_STRING)
.withUserConfiguration(AzureServiceBusAutoConfiguration.class)
.run(context -> {
assertThat(context.getBean(ServiceBusConnectionStringProvider.class).getConnectionString()).isEqualTo("str1");
assertThat(context.getBean(ServiceBusConnectionStringProvider.class).getConnectionString()).isEqualTo(NAMESPACE_CONNECTION_STRING);
assertThat(context).doesNotHaveBean(ServiceBusNamespaceManager.class);
assertThat(context).doesNotHaveBean(ServiceBusQueueManager.class);
assertThat(context).hasSingleBean(ServiceBusQueueClientFactory.class);
Expand Down Expand Up @@ -104,7 +126,7 @@ public void testMessageConverterProvided() {
TestConfigWithMessageConverter.class,
AzureServiceBusAutoConfiguration.class)
.withPropertyValues(
SERVICE_BUS_PROPERTY_PREFIX + "connection-string=str1"
SERVICE_BUS_PROPERTY_PREFIX + "connection-string" + NAMESPACE_CONNECTION_STRING
)
.run(context -> {
assertThat(context).hasSingleBean(ServiceBusMessageConverter.class);
Expand Down Expand Up @@ -133,7 +155,7 @@ public static class TestConfigWithConnectionStringProvider {

@Bean
public ServiceBusConnectionStringProvider serviceBusConnectionStringProvider() {
return new ServiceBusConnectionStringProvider("fake");
return new ServiceBusConnectionStringProvider(NAMESPACE_CONNECTION_STRING);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.spring.cloud.autoconfigure.servicebus;

import com.azure.messaging.servicebus.ServiceBusProcessorClient;
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.cloud.context.core.config.AzureProperties;
import com.azure.spring.cloud.context.core.impl.ServiceBusNamespaceManager;
Expand All @@ -13,7 +14,6 @@
import com.azure.spring.integration.servicebus.factory.ServiceBusTopicClientFactory;
import com.azure.spring.integration.servicebus.topic.ServiceBusTopicOperation;
import com.azure.spring.integration.servicebus.topic.ServiceBusTopicTemplate;
import com.microsoft.azure.servicebus.TopicClient;
import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand All @@ -22,6 +22,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.azure.spring.cloud.autoconfigure.servicebus.AzureServiceBusQueueAutoConfigurationTest.NAMESPACE_CONNECTION_STRING;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
Expand All @@ -42,7 +43,7 @@ public void testAzureServiceBusTopicDisabled() {

@Test
public void testWithoutAzureServiceBusTopicClient() {
this.contextRunner.withClassLoader(new FilteredClassLoader(TopicClient.class))
this.contextRunner.withClassLoader(new FilteredClassLoader(ServiceBusProcessorClient.class))
.run(context -> assertThat(context).doesNotHaveBean(ServiceBusTopicOperation.class));
}

Expand Down Expand Up @@ -70,10 +71,10 @@ public void testTopicClientFactoryCreated() {

@Test
public void testConnectionStringProvided() {
this.contextRunner.withPropertyValues(SERVICE_BUS_PROPERTY_PREFIX + "connection-string=str1")
this.contextRunner.withPropertyValues(SERVICE_BUS_PROPERTY_PREFIX + "connection-string=" + NAMESPACE_CONNECTION_STRING)
.withUserConfiguration(AzureServiceBusAutoConfiguration.class)
.run(context -> {
assertThat(context.getBean(ServiceBusConnectionStringProvider.class).getConnectionString()).isEqualTo("str1");
assertThat(context.getBean(ServiceBusConnectionStringProvider.class).getConnectionString()).isEqualTo(NAMESPACE_CONNECTION_STRING);
assertThat(context).doesNotHaveBean(ServiceBusNamespaceManager.class);
assertThat(context).doesNotHaveBean(ServiceBusTopicManager.class);
assertThat(context).doesNotHaveBean(ServiceBusTopicSubscriptionManager.class);
Expand Down Expand Up @@ -105,7 +106,7 @@ public void testMessageConverterProvided() {
TestConfigWithMessageConverter.class,
AzureServiceBusAutoConfiguration.class)
.withPropertyValues(
SERVICE_BUS_PROPERTY_PREFIX + "connection-string=str1"
SERVICE_BUS_PROPERTY_PREFIX + "connection-string=" + NAMESPACE_CONNECTION_STRING
)
.run(context -> {
assertThat(context).hasSingleBean(ServiceBusMessageConverter.class);
Expand Down Expand Up @@ -134,7 +135,7 @@ public static class TestConfigWithConnectionStringProvider {

@Bean
public ServiceBusConnectionStringProvider serviceBusConnectionStringProvider() {
return new ServiceBusConnectionStringProvider("fake");
return new ServiceBusConnectionStringProvider(NAMESPACE_CONNECTION_STRING);
}

}
Expand Down
12 changes: 6 additions & 6 deletions sdk/spring/azure-spring-cloud-context/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@
</dependency>

<!-- test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version> <!-- {x-version-update;junit:junit;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -91,6 +85,12 @@
<version>2.4.5</version> <!-- {x-version-update;org.springframework.boot:spring-boot-starter-test;external_dependency} -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.vintage:junit-vintage-engine;external_dependency} -->
<scope>test</scope>
</dependency>

<!-- Added this dependency to include necessary annotations used by reactor core.
Without this dependency, javadoc throws a warning as it cannot find enum When.MAYBE
Expand Down
20 changes: 3 additions & 17 deletions sdk/spring/azure-spring-cloud-starter-servicebus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,13 @@
<version>2.5.0-beta.1</version> <!-- {x-version-update;com.azure.spring:azure-spring-integration-servicebus;current} -->
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>3.6.1</version> <!-- {x-version-update;com.microsoft.azure:azure-servicebus;external_dependency} -->
<groupId>com.azure</groupId>
<artifactId>azure-messaging-servicebus</artifactId>
<version>7.2.0</version> <!-- {x-version-update;com.azure:azure-messaging-servicebus;dependency} -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version> <!-- {x-version-update;org.apache.maven.plugins:maven-enforcer-plugin;external_dependency} -->
<configuration>
<rules>
<bannedDependencies>
<includes>
<include>com.microsoft.azure:azure-servicebus:[3.6.1]</include> <!-- {x-include-update;com.microsoft.azure:azure-servicebus;external_dependency} -->
</includes>
</bannedDependencies>
</rules>
</configuration>
</plugin>
<!-- BEGIN: Empty Java Doc & Sources -->
<!-- The following code will generate an empty javadoc with just a README.md. This is necessary
to pass the required checks on Maven. The way this works is by setting the classesDirectory
Expand Down
6 changes: 3 additions & 3 deletions sdk/spring/azure-spring-cloud-storage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version> <!-- {x-version-update;junit:junit;external_dependency} -->
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.1</version> <!-- {x-version-update;org.junit.vintage:junit-vintage-engine;external_dependency} -->
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<version>2.5.0-beta.1</version> <!-- {x-version-update;com.azure.spring:azure-spring-cloud-starter-servicebus;current} -->
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-servicebus</artifactId>
<version>3.6.1</version> <!-- {x-version-update;com.microsoft.azure:azure-servicebus;external_dependency} -->
<groupId>com.azure</groupId>
<artifactId>azure-messaging-servicebus</artifactId>
<version>7.2.0</version> <!-- {x-version-update;com.azure:azure-messaging-servicebus;dependency} -->
</dependency>
<!-- Added this dependency to include necessary annotations used by reactor core.
Without this dependency, javadoc throws a warning as it cannot find enum When.MAYBE
Expand All @@ -63,7 +63,6 @@
<rules>
<bannedDependencies>
<includes>
<include>com.microsoft.azure:azure-servicebus:[3.6.1]</include> <!-- {x-include-update;com.microsoft.azure:azure-servicebus;external_dependency} -->
<include>org.springframework.cloud:spring-cloud-stream:[3.1.2]</include> <!-- {x-include-update;org.springframework.cloud:spring-cloud-stream;external_dependency} -->
</includes>
</bannedDependencies>
Expand Down
Loading

0 comments on commit 2466b8b

Please sign in to comment.