Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor spring messaging storage queue #26472

8 changes: 5 additions & 3 deletions sdk/spring/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
- Supported spring-cloud version: 2021.0.0

### Features Added

### Breaking Changes
- Support StorageQueueMessageConverter as a bean to support customize ObjectMapper.
- Support EventHubsMessageConverter as a bean to support customize ObjectMapper.

### Dependency Updates
Upgrade dependency according to spring-boot-dependencies:2.6.1 and spring-cloud-dependencies:2021.0.0
Expand All @@ -19,7 +19,9 @@ Upgrade dependency according to spring-boot-dependencies:2.6.1 and spring-cloud-
5. Property name "spring.cloud.azure.active-directory.graph-base-uri" changed to "spring.cloud.azure.active-directory.profile.environment.microsoft-graph-endpoint".
6. Property name "spring.cloud.azure.active-directory.graph-membership-uri" changed to "spring.cloud.azure.active-directory.profile.environment.microsoft-graph-endpoint" and "spring.cloud.azure.active-directory.user-group.use-transitive-members".
7. Remove artifact id `spring-cloud-azure-stream-binder-test`.

8. Remove `StorageQueueOperation`.
9. Remove configuration of checkpoint mode for StorageQueueTemplate, and support only MANUAL mode.
10. Remove auto creating Storage Queue when send/receive messages via `StorageQueueTemplate`.
### Bugs Fixed

### Other Changes
Expand Down
3 changes: 2 additions & 1 deletion sdk/spring/spring-cloud-azure-autoconfigure/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## 4.0.0-beta.3 (Unreleased)

### Features Added

- Support StorageQueueMessageConverter as a bean to support customize ObjectMapper.
- Support EventHubsMessageConverter as a bean to support customize ObjectMapper.
### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.azure.spring.cloud.autoconfigure.condition.ConditionalOnMissingProperty;
import com.azure.spring.cloud.autoconfigure.eventhubs.properties.AzureEventHubsProperties;
import com.azure.spring.resourcemanager.connectionstring.EventHubsArmConnectionStringProvider;
import com.azure.spring.resourcemanager.provisioner.eventhubs.DefaultEventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioner.eventhubs.EventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioning.eventhubs.DefaultEventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioning.eventhubs.EventHubsProvisioner;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.azure.spring.cloud.autoconfigure.condition.ConditionalOnMissingProperty;
import com.azure.spring.cloud.autoconfigure.servicebus.properties.AzureServiceBusProperties;
import com.azure.spring.resourcemanager.connectionstring.ServiceBusArmConnectionStringProvider;
import com.azure.spring.resourcemanager.provisioner.servicebus.DefaultServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioner.servicebus.ServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioning.servicebus.DefaultServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioning.servicebus.ServiceBusProvisioner;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
package com.azure.spring.cloud.autoconfigure.storage;

import com.azure.spring.cloud.autoconfigure.storage.queue.AzureStorageQueueAutoConfiguration;
import com.azure.spring.storage.queue.core.DefaultStorageQueueClientFactory;
import com.azure.spring.storage.queue.core.StorageQueueClientFactory;
import com.azure.spring.storage.queue.core.StorageQueueOperation;
import com.azure.spring.cloud.autoconfigure.storage.queue.properties.AzureStorageQueueProperties;
import com.azure.spring.storage.queue.core.StorageQueueTemplate;
import com.azure.spring.storage.queue.core.factory.DefaultStorageQueueClientFactory;
import com.azure.spring.storage.queue.core.factory.StorageQueueClientFactory;
import com.azure.spring.storage.queue.core.properties.StorageQueueProperties;
import com.azure.spring.storage.queue.support.converter.StorageQueueMessageConverter;
import com.azure.storage.queue.QueueServiceAsyncClient;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -18,26 +19,31 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.azure.spring.core.util.AzurePropertiesUtils.copyAzureCommonProperties;

/**
* Auto-configuration class for Azure Storage Queue.
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(StorageQueueClientFactory.class)
@ConditionalOnProperty(value = "spring.cloud.azure.storage.queue.enabled", havingValue = "true", matchIfMissing = true)
@ConditionalOnBean(QueueServiceAsyncClient.class)
@ConditionalOnBean(AzureStorageQueueProperties.class)
@AutoConfigureAfter(AzureStorageQueueAutoConfiguration.class)
public class AzureStorageQueueOperationAutoConfiguration {
public class AzureStorageQueueMessagingAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public StorageQueueClientFactory storageQueueClientFactory(QueueServiceAsyncClient queueServiceAsyncClient) {
return new DefaultStorageQueueClientFactory(queueServiceAsyncClient);
public StorageQueueClientFactory storageQueueClientFactory(AzureStorageQueueProperties properties) {
StorageQueueProperties storageQueueProperties = new StorageQueueProperties();
BeanUtils.copyProperties(properties, storageQueueProperties);
copyAzureCommonProperties(properties, storageQueueProperties);
return new DefaultStorageQueueClientFactory(storageQueueProperties);
}

@Bean
@ConditionalOnMissingBean
public StorageQueueOperation storageQueueOperation(StorageQueueClientFactory storageQueueClientFactory,
StorageQueueMessageConverter messageConverter) {
public StorageQueueTemplate storageQueueTemplate(StorageQueueClientFactory storageQueueClientFactory,
StorageQueueMessageConverter messageConverter) {
StorageQueueTemplate storageQueueTemplate = new StorageQueueTemplate(storageQueueClientFactory);
storageQueueTemplate.setMessageConverter(messageConverter);
return storageQueueTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class AzureStorageQueueProperties extends AzureStorageProperties implemen
*/
private String queueName;


public String getEndpoint() {
return endpoint == null ? buildEndpointFromAccountName() : endpoint;
}
Expand All @@ -38,6 +37,7 @@ private String buildEndpointFromAccountName() {
return String.format(QUEUE_ENDPOINT_PATTERN, accountName, profile.getEnvironment().getStorageEndpointSuffix());
}

@Override
public QueueServiceVersion getServiceVersion() {
return serviceVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ com.azure.spring.cloud.autoconfigure.storage.blob.AzureStorageBlobResourceAutoCo
com.azure.spring.cloud.autoconfigure.storage.fileshare.AzureStorageFileShareAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.storage.fileshare.AzureStorageFileShareResourceAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.storage.queue.AzureStorageQueueAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.storage.AzureStorageQueueOperationAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.storage.AzureStorageQueueMessagingAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.trace.sleuth.AzureSleuthAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.resourcemanager.AzureResourceManagerAutoConfiguration,\
com.azure.spring.cloud.autoconfigure.resourcemanager.AzureEventHubsResourceManagerAutoConfiguration,\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.spring.cloud.autoconfigure.eventhubs.properties.AzureEventHubsProperties;
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.resourcemanager.connectionstring.EventHubsArmConnectionStringProvider;
import com.azure.spring.resourcemanager.provisioner.eventhubs.EventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioning.eventhubs.EventHubsProvisioner;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.spring.cloud.autoconfigure.properties.AzureGlobalProperties;
import com.azure.spring.cloud.autoconfigure.servicebus.properties.AzureServiceBusProperties;
import com.azure.spring.resourcemanager.connectionstring.ServiceBusArmConnectionStringProvider;
import com.azure.spring.resourcemanager.provisioner.servicebus.ServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioning.servicebus.ServiceBusProvisioner;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.resourcemanager.provisioner.eventhubs;
package com.azure.spring.resourcemanager.provisioning.eventhubs;

import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.resourcemanager.provisioner.eventhubs;
package com.azure.spring.resourcemanager.provisioning.eventhubs;

/**
* An interface to provision Event Hubs resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/**
* Event Hubs resource provisioner.
*/
package com.azure.spring.resourcemanager.provisioner.eventhubs;
package com.azure.spring.resourcemanager.provisioning.eventhubs;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.resourcemanager.provisioner.servicebus;
package com.azure.spring.resourcemanager.provisioning.servicebus;

import com.azure.resourcemanager.AzureResourceManager;
import com.azure.spring.core.properties.resource.AzureResourceMetadata;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.resourcemanager.provisioner.servicebus;
package com.azure.spring.resourcemanager.provisioning.servicebus;

/**
* An interface to provision Service Bus queue resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
/**
* Service Bus resource provisioner.
*/
package com.azure.spring.resourcemanager.provisioner.servicebus;
package com.azure.spring.resourcemanager.provisioning.servicebus;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
requires spring.core;

exports com.azure.spring.resourcemanager.connectionstring;
exports com.azure.spring.resourcemanager.provisioner.eventhubs;
exports com.azure.spring.resourcemanager.provisioner.servicebus;
exports com.azure.spring.resourcemanager.provisioning.eventhubs;
exports com.azure.spring.resourcemanager.provisioning.servicebus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public QueueMessageEncoding getMessageEncoding() {
public void setMessageEncoding(QueueMessageEncoding messageEncoding) {
this.messageEncoding = messageEncoding;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 4.0.0-beta.3 (Unreleased)

### Features Added

- Support EventHubsMessageConverter as a bean to support customize ObjectMapper.
### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.azure.spring.cloud.autoconfigure.eventhubs.properties.AzureEventHubsProperties;
import com.azure.spring.cloud.autoconfigure.resourcemanager.AzureEventHubsResourceManagerAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.resourcemanager.AzureResourceManagerAutoConfiguration;
import com.azure.spring.resourcemanager.provisioner.eventhubs.EventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioning.eventhubs.EventHubsProvisioner;
import com.azure.spring.cloud.stream.binder.eventhubs.EventHubsMessageChannelBinder;
import com.azure.spring.cloud.stream.binder.eventhubs.properties.EventHubsExtendedBindingProperties;
import com.azure.spring.cloud.stream.binder.eventhubs.provisioning.EventHubsChannelProvisioner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.spring.cloud.stream.binder.eventhubs.provisioning;

import com.azure.spring.resourcemanager.provisioner.eventhubs.EventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioning.eventhubs.EventHubsProvisioner;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.azure.spring.cloud.stream.binder.eventhubs.properties.EventHubsExtendedBindingProperties;
import com.azure.spring.cloud.stream.binder.eventhubs.provisioning.EventHubsChannelProvisioner;
import com.azure.spring.cloud.stream.binder.eventhubs.provisioning.EventHubsChannelResourceManagerProvisioner;
import com.azure.spring.resourcemanager.provisioner.eventhubs.EventHubsProvisioner;
import com.azure.spring.resourcemanager.provisioning.eventhubs.EventHubsProvisioner;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.azure.spring.cloud.autoconfigure.servicebus.AzureServiceBusAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.servicebus.AzureServiceBusMessagingAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.servicebus.properties.AzureServiceBusProperties;
import com.azure.spring.resourcemanager.provisioner.servicebus.ServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioning.servicebus.ServiceBusProvisioner;
import com.azure.spring.cloud.stream.binder.servicebus.ServiceBusMessageChannelBinder;
import com.azure.spring.cloud.stream.binder.servicebus.properties.ServiceBusExtendedBindingProperties;
import com.azure.spring.cloud.stream.binder.servicebus.provisioning.ServiceBusChannelProvisioner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.spring.cloud.stream.binder.servicebus.provisioning;

import com.azure.spring.resourcemanager.provisioner.servicebus.ServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioning.servicebus.ServiceBusProvisioner;
import com.azure.spring.service.servicebus.properties.ServiceBusEntityType;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.azure.spring.cloud.stream.binder.servicebus.properties.ServiceBusExtendedBindingProperties;
import com.azure.spring.cloud.stream.binder.servicebus.provisioning.ServiceBusChannelProvisioner;
import com.azure.spring.cloud.stream.binder.servicebus.provisioning.ServiceBusChannelResourceManagerProvisioner;
import com.azure.spring.resourcemanager.provisioner.servicebus.ServiceBusProvisioner;
import com.azure.spring.resourcemanager.provisioning.servicebus.ServiceBusProvisioner;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
Expand Down
2 changes: 1 addition & 1 deletion sdk/spring/spring-integration-azure-eventhubs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 4.0.0-beta.3 (Unreleased)

### Features Added

- Support EventHubsMessageConverter as a bean to support customize ObjectMapper.
### Breaking Changes

### Bugs Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
## 4.0.0-beta.3 (Unreleased)

### Features Added

- Support StorageQueueMessageConverter as a bean to support customize ObjectMapper.
### Breaking Changes

- Remove `StorageQueueOperation`.
- Remove configuration of checkpoint mode for StorageQueueTemplate, and support only MANUAL mode.
- Remove auto creating Storage Queue when send/receive messages via `StorageQueueTemplate`.
### Bugs Fixed

### Other Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package com.azure.spring.integration.storage.queue.inbound;

import com.azure.spring.storage.queue.core.StorageQueueOperation;
import com.azure.spring.storage.queue.core.StorageQueueTemplate;
import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
Expand All @@ -15,24 +15,24 @@
*/
public class StorageQueueMessageSource extends AbstractMessageSource<Message<?>> {

private final StorageQueueOperation storageQueueOperation;
private final StorageQueueTemplate storageQueueTemplate;
private final String destination;

/**
* Construct a {@link StorageQueueMessageSource} with the specified destination and {@link StorageQueueOperation}.
* Construct a {@link StorageQueueMessageSource} with the specified destination and {@link StorageQueueTemplate}.
*
* @param destination the destination
* @param storageQueueOperation the storage queue operation
* @param storageQueueTemplate the storage queue operation
*/
public StorageQueueMessageSource(String destination, StorageQueueOperation storageQueueOperation) {
public StorageQueueMessageSource(String destination, StorageQueueTemplate storageQueueTemplate) {
Assert.hasText(destination, "destination can't be null or empty");
this.storageQueueOperation = storageQueueOperation;
this.storageQueueTemplate = storageQueueTemplate;
this.destination = destination;
}

@Override
public Object doReceive() {
return storageQueueOperation.receiveAsync(destination).block();
return storageQueueTemplate.receiveAsync(destination, null).block();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package com.azure.spring.integration.storage.queue;

import com.azure.spring.integration.storage.queue.inbound.StorageQueueMessageSource;
import com.azure.spring.storage.queue.core.StorageQueueOperation;
import com.azure.spring.storage.queue.core.StorageQueueTemplate;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -21,14 +21,15 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class StorageQueueMessageSourceTest {

@Mock
private StorageQueueOperation mockOperation;
private StorageQueueTemplate mockTemplate;
private Message<?> message;

private String destination = "test-destination";
Expand All @@ -49,7 +50,7 @@ public void init() {

@BeforeEach
public void setup() {
messageSource = new StorageQueueMessageSource(destination, mockOperation);
messageSource = new StorageQueueMessageSource(destination, mockTemplate);
}

@AfterAll
Expand All @@ -59,13 +60,13 @@ public void close() throws Exception {

@Test
public void testDoReceiveWhenHaveNoMessage() {
when(this.mockOperation.receiveAsync(eq(destination))).thenReturn(Mono.empty());
when(this.mockTemplate.receiveAsync(eq(destination), any())).thenReturn(Mono.empty());
assertNull(messageSource.doReceive());
}

@Test
public void testDoReceiveSuccess() {
when(this.mockOperation.receiveAsync(eq(destination))).thenReturn(Mono.just(message));
when(this.mockTemplate.receiveAsync(eq(destination), any())).thenReturn(Mono.just(message));
Message<?> receivedMessage = (Message<?>) messageSource.doReceive();
assertEquals(message, receivedMessage);
}
Expand Down
Loading