diff --git a/sdk/spring/CHANGELOG.md b/sdk/spring/CHANGELOG.md index f1ff6ed2fb63c..8e26be33e23e9 100644 --- a/sdk/spring/CHANGELOG.md +++ b/sdk/spring/CHANGELOG.md @@ -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 @@ -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 diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/CHANGELOG.md b/sdk/spring/spring-cloud-azure-autoconfigure/CHANGELOG.md index 21486b9e46a93..353adde573913 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/CHANGELOG.md +++ b/sdk/spring/spring-cloud-azure-autoconfigure/CHANGELOG.md @@ -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 diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfiguration.java index 52f762c95f4ba..e98c266aba505 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfiguration.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfiguration.java index 1f74621e76538..2381be2a14b3f 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfiguration.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/AzureStorageQueueOperationAutoConfiguration.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/AzureStorageQueueMessagingAutoConfiguration.java similarity index 58% rename from sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/AzureStorageQueueOperationAutoConfiguration.java rename to sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/AzureStorageQueueMessagingAutoConfiguration.java index 4f37a2cc381c3..0f4a10394a135 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/AzureStorageQueueOperationAutoConfiguration.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/AzureStorageQueueMessagingAutoConfiguration.java @@ -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; @@ -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; diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/properties/AzureStorageQueueProperties.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/properties/AzureStorageQueueProperties.java index 592c7d36743d3..db2bacdb4192d 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/properties/AzureStorageQueueProperties.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/storage/queue/properties/AzureStorageQueueProperties.java @@ -29,7 +29,6 @@ public class AzureStorageQueueProperties extends AzureStorageProperties implemen */ private String queueName; - public String getEndpoint() { return endpoint == null ? buildEndpointFromAccountName() : endpoint; } @@ -38,6 +37,7 @@ private String buildEndpointFromAccountName() { return String.format(QUEUE_ENDPOINT_PATTERN, accountName, profile.getEnvironment().getStorageEndpointSuffix()); } + @Override public QueueServiceVersion getServiceVersion() { return serviceVersion; } diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/resources/META-INF/spring.factories b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/resources/META-INF/spring.factories index e8fbd8d55ff22..e52c533b14bf2 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/main/resources/META-INF/spring.factories @@ -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,\ diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfigurationTest.java index 4338af39c669f..266e425f6ea7e 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfigurationTest.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfigurationTest.java b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfigurationTest.java index fd705a1913e1a..b4cb31dc1efa4 100644 --- a/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfigurationTest.java +++ b/sdk/spring/spring-cloud-azure-autoconfigure/src/test/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureServiceBusResourceManagerAutoConfigurationTest.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/DefaultEventHubsProvisioner.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/DefaultEventHubsProvisioner.java similarity index 96% rename from sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/DefaultEventHubsProvisioner.java rename to sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/DefaultEventHubsProvisioner.java index 16c827705b113..d6d1f5594c76c 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/DefaultEventHubsProvisioner.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/DefaultEventHubsProvisioner.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/EventHubsProvisioner.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/EventHubsProvisioner.java similarity index 93% rename from sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/EventHubsProvisioner.java rename to sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/EventHubsProvisioner.java index ea387efe06b35..9168e11596329 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/EventHubsProvisioner.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/EventHubsProvisioner.java @@ -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. diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/package-info.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/package-info.java similarity index 68% rename from sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/package-info.java rename to sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/package-info.java index 2410664f14289..45e6a7d83bbe8 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/eventhubs/package-info.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/eventhubs/package-info.java @@ -4,4 +4,4 @@ /** * Event Hubs resource provisioner. */ -package com.azure.spring.resourcemanager.provisioner.eventhubs; +package com.azure.spring.resourcemanager.provisioning.eventhubs; diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/DefaultServiceBusProvisioner.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/DefaultServiceBusProvisioner.java similarity index 96% rename from sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/DefaultServiceBusProvisioner.java rename to sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/DefaultServiceBusProvisioner.java index 78b3b1532645a..7840f1be1fb08 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/DefaultServiceBusProvisioner.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/DefaultServiceBusProvisioner.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/ServiceBusProvisioner.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/ServiceBusProvisioner.java similarity index 93% rename from sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/ServiceBusProvisioner.java rename to sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/ServiceBusProvisioner.java index 19768f9d79a84..d0b3c9a74d4d3 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/ServiceBusProvisioner.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/ServiceBusProvisioner.java @@ -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. diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/package-info.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/package-info.java similarity index 68% rename from sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/package-info.java rename to sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/package-info.java index e8b36df079509..62a5443824fb4 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioner/servicebus/package-info.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/com/azure/spring/resourcemanager/provisioning/servicebus/package-info.java @@ -4,4 +4,4 @@ /** * Service Bus resource provisioner. */ -package com.azure.spring.resourcemanager.provisioner.servicebus; +package com.azure.spring.resourcemanager.provisioning.servicebus; diff --git a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/module-info.java b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/module-info.java index 8badc5877ee82..a8b40902ffd99 100644 --- a/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/module-info.java +++ b/sdk/spring/spring-cloud-azure-resourcemanager/src/main/java/module-info.java @@ -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; } diff --git a/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/implementation/storage/queue/TestAzureStorageQueueProperties.java b/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/implementation/storage/queue/TestAzureStorageQueueProperties.java index 0d399747dc54a..e056f8a4c5e6f 100644 --- a/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/implementation/storage/queue/TestAzureStorageQueueProperties.java +++ b/sdk/spring/spring-cloud-azure-service/src/test/java/com/azure/spring/service/implementation/storage/queue/TestAzureStorageQueueProperties.java @@ -32,4 +32,5 @@ public QueueMessageEncoding getMessageEncoding() { public void setMessageEncoding(QueueMessageEncoding messageEncoding) { this.messageEncoding = messageEncoding; } + } diff --git a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/CHANGELOG.md b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/CHANGELOG.md index 21486b9e46a93..3d56d8ee38be4 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/CHANGELOG.md +++ b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/CHANGELOG.md @@ -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 diff --git a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfiguration.java b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfiguration.java index a1f26d8bdf6c0..dc8111a54a7b8 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfiguration.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfiguration.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/provisioning/EventHubsChannelResourceManagerProvisioner.java b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/provisioning/EventHubsChannelResourceManagerProvisioner.java index ccd4856d27ac3..6a3858eca9562 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/provisioning/EventHubsChannelResourceManagerProvisioner.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/provisioning/EventHubsChannelResourceManagerProvisioner.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfigurationTests.java b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfigurationTests.java index f4dbebb9b4a13..35a0f5df4bc20 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/test/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfigurationTests.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfiguration.java b/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfiguration.java index c3a1fd7a5f857..3d87f9280381b 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfiguration.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfiguration.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/provisioning/ServiceBusChannelResourceManagerProvisioner.java b/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/provisioning/ServiceBusChannelResourceManagerProvisioner.java index a6b29f8648c37..405fbb8c9d7b5 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/provisioning/ServiceBusChannelResourceManagerProvisioner.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/main/java/com/azure/spring/cloud/stream/binder/servicebus/provisioning/ServiceBusChannelResourceManagerProvisioner.java @@ -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; diff --git a/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfigurationTests.java b/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfigurationTests.java index b7113058fe522..5b3f0a6ccae6b 100644 --- a/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfigurationTests.java +++ b/sdk/spring/spring-cloud-azure-stream-binder-servicebus/src/test/java/com/azure/spring/cloud/stream/binder/servicebus/config/ServiceBusBinderConfigurationTests.java @@ -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; diff --git a/sdk/spring/spring-integration-azure-eventhubs/CHANGELOG.md b/sdk/spring/spring-integration-azure-eventhubs/CHANGELOG.md index 21486b9e46a93..3d56d8ee38be4 100644 --- a/sdk/spring/spring-integration-azure-eventhubs/CHANGELOG.md +++ b/sdk/spring/spring-integration-azure-eventhubs/CHANGELOG.md @@ -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 diff --git a/sdk/spring/spring-integration-azure-storage-queue/CHANGELOG.md b/sdk/spring/spring-integration-azure-storage-queue/CHANGELOG.md index 2574773265d54..7d374261888ce 100644 --- a/sdk/spring/spring-integration-azure-storage-queue/CHANGELOG.md +++ b/sdk/spring/spring-integration-azure-storage-queue/CHANGELOG.md @@ -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 diff --git a/sdk/spring/spring-integration-azure-storage-queue/src/main/java/com/azure/spring/integration/storage/queue/inbound/StorageQueueMessageSource.java b/sdk/spring/spring-integration-azure-storage-queue/src/main/java/com/azure/spring/integration/storage/queue/inbound/StorageQueueMessageSource.java index 0b8d296ea8184..01c482bc1ac84 100644 --- a/sdk/spring/spring-integration-azure-storage-queue/src/main/java/com/azure/spring/integration/storage/queue/inbound/StorageQueueMessageSource.java +++ b/sdk/spring/spring-integration-azure-storage-queue/src/main/java/com/azure/spring/integration/storage/queue/inbound/StorageQueueMessageSource.java @@ -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; @@ -15,24 +15,24 @@ */ public class StorageQueueMessageSource extends AbstractMessageSource> { - 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 diff --git a/sdk/spring/spring-integration-azure-storage-queue/src/test/java/com/azure/spring/integration/storage/queue/StorageQueueMessageSourceTest.java b/sdk/spring/spring-integration-azure-storage-queue/src/test/java/com/azure/spring/integration/storage/queue/StorageQueueMessageSourceTest.java index a68f4fe6bb084..4c298975b206d 100644 --- a/sdk/spring/spring-integration-azure-storage-queue/src/test/java/com/azure/spring/integration/storage/queue/StorageQueueMessageSourceTest.java +++ b/sdk/spring/spring-integration-azure-storage-queue/src/test/java/com/azure/spring/integration/storage/queue/StorageQueueMessageSourceTest.java @@ -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; @@ -21,6 +21,7 @@ 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; @@ -28,7 +29,7 @@ public class StorageQueueMessageSourceTest { @Mock - private StorageQueueOperation mockOperation; + private StorageQueueTemplate mockTemplate; private Message message; private String destination = "test-destination"; @@ -49,7 +50,7 @@ public void init() { @BeforeEach public void setup() { - messageSource = new StorageQueueMessageSource(destination, mockOperation); + messageSource = new StorageQueueMessageSource(destination, mockTemplate); } @AfterAll @@ -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); } diff --git a/sdk/spring/spring-messaging-azure-eventhubs/CHANGELOG.md b/sdk/spring/spring-messaging-azure-eventhubs/CHANGELOG.md index 21486b9e46a93..3d56d8ee38be4 100644 --- a/sdk/spring/spring-messaging-azure-eventhubs/CHANGELOG.md +++ b/sdk/spring/spring-messaging-azure-eventhubs/CHANGELOG.md @@ -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 diff --git a/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/servicebus/core/ServiceBusTemplate.java b/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/servicebus/core/ServiceBusTemplate.java index cdc25dbf02cf0..9e1191170160b 100644 --- a/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/servicebus/core/ServiceBusTemplate.java +++ b/sdk/spring/spring-messaging-azure-servicebus/src/main/java/com/azure/spring/servicebus/core/ServiceBusTemplate.java @@ -68,7 +68,7 @@ public void setMessageConverter(ServiceBusMessageConverter messageConverter) { /** * Get the message converter. - * @return the message conveter. + * @return the message converter. */ public ServiceBusMessageConverter getMessageConverter() { return messageConverter; diff --git a/sdk/spring/spring-messaging-azure-storage-queue/CHANGELOG.md b/sdk/spring/spring-messaging-azure-storage-queue/CHANGELOG.md index 2574773265d54..844adbd3038c6 100644 --- a/sdk/spring/spring-messaging-azure-storage-queue/CHANGELOG.md +++ b/sdk/spring/spring-messaging-azure-storage-queue/CHANGELOG.md @@ -3,9 +3,12 @@ ## 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`. +- Add the parameter of visibility timeout for StorageQueueTemplate#receiveAsync ### Bugs Fixed ### Other Changes diff --git a/sdk/spring/spring-messaging-azure-storage-queue/pom.xml b/sdk/spring/spring-messaging-azure-storage-queue/pom.xml index b4acb97b052b0..dbe8ba21e4797 100644 --- a/sdk/spring/spring-messaging-azure-storage-queue/pom.xml +++ b/sdk/spring/spring-messaging-azure-storage-queue/pom.xml @@ -76,6 +76,12 @@ 5.8.1 test + + org.springframework.boot + spring-boot-starter-test + 2.6.1 + test + com.fasterxml.jackson.core jackson-databind diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactory.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactory.java deleted file mode 100644 index a047e043f8c56..0000000000000 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.spring.storage.queue.core; - -import com.azure.spring.core.util.Memoizer; -import com.azure.storage.queue.QueueAsyncClient; -import com.azure.storage.queue.QueueServiceAsyncClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.lang.NonNull; - -import java.util.function.Function; - -/** - * The {@link StorageQueueClientFactory} implementation to produce new {@link QueueAsyncClient} instances - * for provided {@link QueueServiceAsyncClient} on each {@link #createQueueClient} invocation. - */ -public final class DefaultStorageQueueClientFactory implements StorageQueueClientFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultStorageQueueClientFactory.class); - private final Function queueClientCreator = Memoizer.memoize(this::createQueueClient); - private final QueueServiceAsyncClient queueServiceAsyncClient; - - /** - * Construct a factory with the provided {@link QueueServiceAsyncClient}. - * @param queueServiceAsyncClient the queueServiceAsyncClient - */ - public DefaultStorageQueueClientFactory(@NonNull QueueServiceAsyncClient queueServiceAsyncClient) { - this.queueServiceAsyncClient = queueServiceAsyncClient; - } - - @Override - public QueueAsyncClient getOrCreateQueueClient(String queueName) { - return this.queueClientCreator.apply(queueName); - } - - private QueueAsyncClient createQueueClient(String queueName) { - // TODO (xiada): the application id - final QueueAsyncClient queueClient = queueServiceAsyncClient.getQueueAsyncClient(queueName); - - - // TODO (xiada): when used with connection string, this call will throw exception - // TODO (xiada): https://github.com/Azure/azure-sdk-for-java/issues/15008 - queueClient.create().subscribe( - response -> { - }, - e -> LOGGER.error("Fail to create the queue.", e), - () -> LOGGER.info("Complete creating the queue!") - ); - - return queueClient; - } - -} diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueClientFactory.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueClientFactory.java deleted file mode 100644 index 59f0311c91858..0000000000000 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueClientFactory.java +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.spring.storage.queue.core; - -import com.azure.storage.queue.QueueAsyncClient; - -/** - * The strategy to produce {@link QueueAsyncClient} instance. - */ -public interface StorageQueueClientFactory { - - /** - * Create {@link QueueAsyncClient} to send to Storage Queue. - * @param queueName the queue name - * @return the QueueAsyncClient. - */ - QueueAsyncClient getOrCreateQueueClient(String queueName); -} diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueOperation.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueOperation.java deleted file mode 100644 index 87c823af2941c..0000000000000 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueOperation.java +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.spring.storage.queue.core; - -import com.azure.spring.messaging.core.ReceiveOperation; -import com.azure.spring.messaging.core.SendOperation; - -import java.time.Duration; - -/** - * Azure storage queue operation to support send and receive - * {@link org.springframework.messaging.Message} asynchronously - *

- * You should checkpoint if message has been processed successfully, otherwise it will be visible again after certain - * time specified by {@link #setVisibilityTimeout(Duration)}. - * - */ -public interface StorageQueueOperation extends SendOperation, ReceiveOperation { - - /** - * Set visibility timeout. Default is 30 - * - * @param visibilityTimeoutDuration visibility timeout - */ - void setVisibilityTimeout(Duration visibilityTimeoutDuration); -} diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueTemplate.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueTemplate.java index 04e06ccdedb05..0319cbe264588 100644 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueTemplate.java +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/StorageQueueTemplate.java @@ -6,8 +6,9 @@ import com.azure.spring.messaging.AzureHeaders; import com.azure.spring.messaging.PartitionSupplier; import com.azure.spring.messaging.checkpoint.AzureCheckpointer; -import com.azure.spring.messaging.checkpoint.CheckpointMode; import com.azure.spring.messaging.checkpoint.Checkpointer; +import com.azure.spring.messaging.core.SendOperation; +import com.azure.spring.storage.queue.core.factory.StorageQueueClientFactory; import com.azure.spring.storage.queue.support.StorageQueueHelper; import com.azure.spring.storage.queue.support.converter.StorageQueueMessageConverter; import com.azure.storage.queue.QueueAsyncClient; @@ -25,71 +26,57 @@ import java.util.Map; /** - * Azure Storage Queue template to support send / receive {@link Message} asynchronously. + * Azure Storage Queue template to support send / receive {@link Message}s asynchronously. + * + * You should checkpoint if message has been processed successfully, otherwise it will be visible again after certain + * time specified by {@link #receiveAsync(String, Duration)} }. */ -public class StorageQueueTemplate implements StorageQueueOperation { +public class StorageQueueTemplate implements SendOperation { private static final Logger LOG = LoggerFactory.getLogger(StorageQueueTemplate.class); - private static final Duration DEFAULT_VISIBILITY_TIMEOUT_IN_SECONDS = Duration.ofSeconds(30); private static final String MSG_FAIL_CHECKPOINT = "Failed to checkpoint %s in storage queue '%s'"; - private static final String MSG_SUCCESS_CHECKPOINT = "Checkpointed %s in storage queue '%s' in %s mode"; + private static final String MSG_SUCCESS_CHECKPOINT = "Checkpointed %s in storage queue '%s'"; private final StorageQueueClientFactory storageQueueClientFactory; private StorageQueueMessageConverter messageConverter = new StorageQueueMessageConverter(); - private Duration visibilityTimeout = DEFAULT_VISIBILITY_TIMEOUT_IN_SECONDS; - private Class messagePayloadType = byte[].class; - private CheckpointMode checkpointMode = CheckpointMode.RECORD; - /** * Create an instance using the supplied StorageQueueClientFactory. * @param storageQueueClientFactory the StorageQueueClientFactory. */ public StorageQueueTemplate(@NonNull StorageQueueClientFactory storageQueueClientFactory) { this.storageQueueClientFactory = storageQueueClientFactory; - LOG.info("StorageQueueTemplate started with properties {}", buildProperties()); + LOG.info("StorageQueueTemplate started with default properties {}", buildProperties()); } @Override - public Mono sendAsync(String queueName, @NonNull Message message, - PartitionSupplier partitionSupplier) { + public Mono sendAsync(String queueName, @NonNull Message message, PartitionSupplier partitionSupplier) { Assert.hasText(queueName, "queueName can't be null or empty"); QueueMessageItem queueMessageItem = messageConverter.fromMessage(message, QueueMessageItem.class); - QueueAsyncClient queueClient = storageQueueClientFactory.getOrCreateQueueClient(queueName); + QueueAsyncClient queueClient = storageQueueClientFactory.createQueueClient(queueName); Assert.notNull(queueMessageItem, "queueMessageItem can't be null"); return queueClient.sendMessage(queueMessageItem.getBody().toString()).then(); } - @Override - public Mono> receiveAsync(String queueName) { - return this.receiveAsync(queueName, visibilityTimeout); - } - - private Mono> receiveAsync(String queueName, Duration visibilityTimeout) { + /** + * Receive a message from the queue asynchronously. + * @param queueName the queue + * @param visibilityTimeout The timeout period for how long the message is invisible in the queue. If left empty + * the dequeued messages will be invisible for 30 seconds. The timeout must be between 1 second and 7 days. + * @return {@link Mono} of the next available {@link Message} or {@code null} if empty + */ + public Mono> receiveAsync(String queueName, Duration visibilityTimeout) { Assert.hasText(queueName, "queueName can't be null or empty"); - - - QueueAsyncClient queueClient = storageQueueClientFactory.getOrCreateQueueClient(queueName); - - + QueueAsyncClient queueClient = storageQueueClientFactory.createQueueClient(queueName); return queueClient.receiveMessages(1, visibilityTimeout) .next() .map(messageItem -> { - Map headers = new HashMap<>(); Checkpointer checkpointer = new AzureCheckpointer(() -> checkpoint(queueClient, messageItem)); - - if (checkpointMode == CheckpointMode.RECORD) { - checkpointer.success().subscribe(); - } else if (checkpointMode == CheckpointMode.MANUAL) { - headers.put(AzureHeaders.CHECKPOINTER, checkpointer); - } - + headers.put(AzureHeaders.CHECKPOINTER, checkpointer); return messageConverter.toMessage(messageItem, new MessageHeaders(headers), messagePayloadType); }); - - } private Mono checkpoint(QueueAsyncClient queueClient, QueueMessageItem messageItem) { @@ -110,24 +97,16 @@ private Mono checkpoint(QueueAsyncClient queueClient, QueueMessageItem mes private Map buildProperties() { Map properties = new HashMap<>(); - properties.put("visibilityTimeout", this.visibilityTimeout); properties.put("messagePayloadType", this.messagePayloadType); - properties.put("checkpointMode", this.checkpointMode); - return properties; } - private boolean isValidCheckpointMode(CheckpointMode checkpointMode) { - return checkpointMode == CheckpointMode.MANUAL || checkpointMode == CheckpointMode.RECORD; - } - private String buildCheckpointFailMessage(QueueMessageItem cloudQueueMessage, String queueName) { return String.format(MSG_FAIL_CHECKPOINT, StorageQueueHelper.toString(cloudQueueMessage), queueName); } private String buildCheckpointSuccessMessage(QueueMessageItem cloudQueueMessage, String queueName) { - return String.format(MSG_SUCCESS_CHECKPOINT, StorageQueueHelper.toString(cloudQueueMessage), queueName, - checkpointMode); + return String.format(MSG_SUCCESS_CHECKPOINT, StorageQueueHelper.toString(cloudQueueMessage), queueName); } /** @@ -146,21 +125,6 @@ public void setMessageConverter(StorageQueueMessageConverter messageConverter) { this.messageConverter = messageConverter; } - /** - * Get the {@code visibilityTimeoutInSeconds}. - * @return the visibilityTimeoutInSeconds. - */ - public Duration getVisibilityTimeout() { - return visibilityTimeout; - } - - @Override - public void setVisibilityTimeout(Duration visibilityTimeoutDuration) { - Assert.state(visibilityTimeoutDuration.isNegative() || visibilityTimeoutDuration.isZero(), "VisibilityTimeoutInSeconds should be positive"); - this.visibilityTimeout = visibilityTimeoutDuration; - LOG.info("StorageQueueTemplate VisibilityTimeout becomes: {} seconds", this.visibilityTimeout.getSeconds()); - } - /** * Get the {@code messagePayloadType}. * @return the messagePayloadType. @@ -169,25 +133,13 @@ public Class getMessagePayloadType() { return messagePayloadType; } - @Override + /** + * Set message payload type. Default is {@code byte[]} + * @param payloadType message payload type + */ public void setMessagePayloadType(Class payloadType) { this.messagePayloadType = payloadType; LOG.info("StorageQueueTemplate messagePayloadType becomes: {}", this.messagePayloadType); } - /** - * Get the {@code checkpointMode}. - * @return the {@code checkpointMode}. - */ - public CheckpointMode getCheckpointMode() { - return checkpointMode; - } - - @Override - public void setCheckpointMode(CheckpointMode checkpointMode) { - Assert.state(isValidCheckpointMode(checkpointMode), - "Only MANUAL or RECORD checkpoint mode is supported in StorageQueueTemplate"); - this.checkpointMode = checkpointMode; - LOG.info("StorageQueueTemplate checkpoint mode becomes: {}", this.checkpointMode); - } } diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/DefaultStorageQueueClientFactory.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/DefaultStorageQueueClientFactory.java new file mode 100644 index 0000000000000..be58441d5a366 --- /dev/null +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/DefaultStorageQueueClientFactory.java @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.storage.queue.core.factory; + +import com.azure.spring.core.AzureSpringIdentifier; +import com.azure.spring.service.implementation.storage.queue.QueueServiceClientBuilderFactory; +import com.azure.spring.storage.queue.core.properties.StorageQueueProperties; +import com.azure.storage.queue.QueueAsyncClient; +import com.azure.storage.queue.QueueServiceAsyncClient; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.lang.NonNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * The {@link StorageQueueClientFactory} implementation to produce new {@link QueueAsyncClient} instances + * for provided {@link QueueServiceAsyncClient} on each {@link #createQueueClient} invocation. + */ +public final class DefaultStorageQueueClientFactory implements StorageQueueClientFactory, DisposableBean { + + private final List listeners = new ArrayList<>(); + private final Map clients = new ConcurrentHashMap<>(); + private final QueueServiceAsyncClient queueServiceAsyncClient; + private final StorageQueueProperties storageQueueProperties; + + /** + * Construct a factory with the provided {@link StorageQueueProperties}. + * @param storageQueueProperties the storage queue properties + */ + public DefaultStorageQueueClientFactory(@NonNull StorageQueueProperties storageQueueProperties) { + this.storageQueueProperties = storageQueueProperties; + QueueServiceClientBuilderFactory queueServiceClientBuilderFactory = + new QueueServiceClientBuilderFactory(this.storageQueueProperties); + queueServiceClientBuilderFactory.setSpringIdentifier(AzureSpringIdentifier.AZURE_SPRING_INTEGRATION_STORAGE_QUEUE); + this.queueServiceAsyncClient = queueServiceClientBuilderFactory.build().buildAsyncClient(); + } + + @Override + public QueueAsyncClient createQueueClient(String queueName) { + return clients.computeIfAbsent(queueName, q -> { + final QueueAsyncClient queueClient = queueServiceAsyncClient.getQueueAsyncClient(queueName); + this.listeners.forEach(l -> l.queueClientAdded(queueName, queueClient)); + return queueClient; + }); + } + + @Override + public void addListener(Listener listener) { + this.listeners.add(listener); + } + + @Override + public boolean removeListener(Listener listener) { + return this.listeners.remove(listener); + } + + @Override + public void destroy() { + clients.forEach((name, client) -> { + listeners.forEach(l -> l.queueClientRemoved(name, client)); + }); + this.clients.clear(); + this.listeners.clear(); + } + +} diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/StorageQueueClientFactory.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/StorageQueueClientFactory.java new file mode 100644 index 0000000000000..f99d44989ab0c --- /dev/null +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/StorageQueueClientFactory.java @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.spring.storage.queue.core.factory; + +import com.azure.storage.queue.QueueAsyncClient; + +/** + * The strategy to produce {@link QueueAsyncClient} instance. + */ +public interface StorageQueueClientFactory { + + /** + * Create {@link QueueAsyncClient} to send and receive messages to/from Storage Queue. + * @param queueName the queue name + * @return the QueueAsyncClient. + */ + QueueAsyncClient createQueueClient(String queueName); + + /** + * Add a listener for this factory. + * @param listener the listener + */ + default void addListener(Listener listener) { + + } + + /** + * Remove a listener + * @param listener the listener + * @return true if removed. + */ + default boolean removeListener(Listener listener) { + return false; + } + + /** + * Called whenever a {@link QueueAsyncClient} is added or removed. + */ + @FunctionalInterface + interface Listener { + + /** + * The callback method that the queue client has been added. + * @param name the name for the queue. + * @param client the queue client. + */ + void queueClientAdded(String name, QueueAsyncClient client); + + /** + * The default callback method that the queue client has been removed. + * @param name the name for the queue. + * @param client the queue client. + */ + default void queueClientRemoved(String name, QueueAsyncClient client) { + } + + } + +} diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/package-info.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/package-info.java new file mode 100644 index 0000000000000..f04c4c0bb1b76 --- /dev/null +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/factory/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Spring Messaging Storage Queue factory package. + */ +package com.azure.spring.storage.queue.core.factory; diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/properties/StorageQueueProperties.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/properties/StorageQueueProperties.java new file mode 100644 index 0000000000000..3b7b27289b183 --- /dev/null +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/properties/StorageQueueProperties.java @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.spring.storage.queue.core.properties; + +import com.azure.spring.core.properties.AzureHttpSdkProperties; +import com.azure.spring.service.implementation.storage.queue.QueueServiceClientProperties; +import com.azure.storage.queue.QueueMessageEncoding; +import com.azure.storage.queue.QueueServiceVersion; + +/** + * Properties for Azure Storage Queue service. + */ +public class StorageQueueProperties extends AzureHttpSdkProperties implements QueueServiceClientProperties { + + public static final String QUEUE_ENDPOINT_PATTERN = "https://%s.queue%s"; + + /** + * Endpoint for Azure Storage service. + */ + protected String endpoint; + /** + * Storage account access key. + */ + protected String accountKey; + + /** + * Shared access signatures (SAS) token used to authorize requests sent to the service. + */ + protected String sasToken; + + /** + * Connection string to connect to the service. + */ + protected String connectionString; + + /** + * Name for the storage account. + */ + protected String accountName; + + /** + * Queue service version used when making API requests. + */ + private QueueServiceVersion serviceVersion; + /** + * How queue message body is represented in HTTP requests and responses. + */ + private QueueMessageEncoding messageEncoding; + + @Override + public String getConnectionString() { + return connectionString; + } + + public void setConnectionString(String connectionString) { + this.connectionString = connectionString; + } + + @Override + public String getEndpoint() { + return endpoint == null ? buildEndpointFromAccountName() : endpoint; + } + + private String buildEndpointFromAccountName() { + return String.format(QUEUE_ENDPOINT_PATTERN, accountName, profile.getEnvironment().getStorageEndpointSuffix()); + } + + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + + @Override + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + @Override + public String getAccountKey() { + return accountKey; + } + + public void setAccountKey(String accountKey) { + this.accountKey = accountKey; + } + + @Override + public String getSasToken() { + return sasToken; + } + + public void setSasToken(String sasToken) { + this.sasToken = sasToken; + } + + @Override + public QueueServiceVersion getServiceVersion() { + return serviceVersion; + } + + public void setServiceVersion(QueueServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + } + + @Override + public QueueMessageEncoding getMessageEncoding() { + return messageEncoding; + } + + public void setMessageEncoding(QueueMessageEncoding messageEncoding) { + this.messageEncoding = messageEncoding; + } + +} diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/properties/package-info.java b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/properties/package-info.java new file mode 100644 index 0000000000000..a69b1381da9bc --- /dev/null +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/main/java/com/azure/spring/storage/queue/core/properties/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Spring Messaging Storage Queue properties abstraction. + */ +package com.azure.spring.storage.queue.core.properties; diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactoryTests.java b/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactoryTests.java index f786b7865f34e..ebefd8d9c3a7e 100644 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactoryTests.java +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/DefaultStorageQueueClientFactoryTests.java @@ -3,30 +3,60 @@ package com.azure.spring.storage.queue.core; +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.storage.queue.QueueAsyncClient; -import com.azure.storage.queue.QueueServiceAsyncClient; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class DefaultStorageQueueClientFactoryTests { + private StorageQueueClientFactory storageQueueClientFactory; + private final String queueName = "queue"; + private int clientAddedTimes; + + @BeforeEach + void setUp() { + StorageQueueProperties storageQueueProperties = new StorageQueueProperties(); + storageQueueProperties.setAccountKey("test-key"); + storageQueueProperties.setAccountName("test-account"); + this.storageQueueClientFactory = new DefaultStorageQueueClientFactory(storageQueueProperties); + clientAddedTimes = 0; + this.storageQueueClientFactory.addListener(new StorageQueueClientFactory.Listener() { + @Override + public void queueClientAdded(String name, QueueAsyncClient client) { + clientAddedTimes++; + } + }); + } + + @Test + void testCreateQueueClient() { + QueueAsyncClient client = storageQueueClientFactory.createQueueClient(queueName); + assertNotNull(client); + assertEquals(1, clientAddedTimes); + } + @Test - void returnSameQueueClientWhenMultiGetQueueClient() { - QueueServiceAsyncClient serviceAsyncClient = mock(QueueServiceAsyncClient.class); - DefaultStorageQueueClientFactory factory = new DefaultStorageQueueClientFactory(serviceAsyncClient); - String queueName = "test-queue"; - QueueAsyncClient queueAsyncClient = mock(QueueAsyncClient.class); - when(queueAsyncClient.create()).thenReturn(Mono.empty()); - when(serviceAsyncClient.getQueueAsyncClient(queueName)).thenReturn(queueAsyncClient); - QueueAsyncClient queueClientFirst = factory.getOrCreateQueueClient(queueName); - QueueAsyncClient queueClientTwo = factory.getOrCreateQueueClient(queueName); - assertEquals(queueClientFirst, queueClientTwo); - verify(serviceAsyncClient, times(1)).getQueueAsyncClient(queueName); + void testCreateQueueClientTwice() { + QueueAsyncClient client = storageQueueClientFactory.createQueueClient(queueName); + assertNotNull(client); + + client = storageQueueClientFactory.createQueueClient(queueName); + assertEquals(1, clientAddedTimes); + } + + @Test + void testRecreateQueueClient() { + QueueAsyncClient client = storageQueueClientFactory.createQueueClient(queueName); + assertNotNull(client); + + QueueAsyncClient client2 = storageQueueClientFactory.createQueueClient("queueName2"); + assertNotNull(client2); + assertEquals(2, clientAddedTimes); } } diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateReceiveTests.java b/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateReceiveTests.java index 804b2e93e8643..671aff56d540b 100644 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateReceiveTests.java +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateReceiveTests.java @@ -10,8 +10,8 @@ import com.azure.core.util.BinaryData; import com.azure.core.util.IterableStream; import com.azure.spring.messaging.AzureHeaders; -import com.azure.spring.messaging.checkpoint.CheckpointMode; import com.azure.spring.messaging.checkpoint.Checkpointer; +import com.azure.spring.storage.queue.core.factory.StorageQueueClientFactory; import com.azure.storage.queue.QueueAsyncClient; import com.azure.storage.queue.models.QueueMessageItem; import com.azure.storage.queue.models.QueueStorageException; @@ -24,14 +24,9 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.time.Duration; -import java.util.Arrays; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @@ -48,9 +43,8 @@ public class StorageQueueTemplateReceiveTests { private StorageQueueClientFactory mockClientFactory; @Mock private QueueAsyncClient mockClient; - private StorageQueueOperation operation; + private StorageQueueTemplate template; private QueueMessageItem queueMessage; - private int visibilityTimeoutInSeconds = 30; private String destination = "queue"; private AutoCloseable closeable; @@ -95,10 +89,10 @@ public IterableStream getElements() { return new IterableStream(flux); } }; - when(this.mockClientFactory.getOrCreateQueueClient(eq(destination))).thenReturn(this.mockClient); + when(this.mockClientFactory.createQueueClient(eq(destination))).thenReturn(this.mockClient); when(this.mockClient.receiveMessages(eq(1), any())) .thenReturn(new PagedFlux<>(() -> Mono.just(pagedResponse))); - this.operation = new StorageQueueTemplate(this.mockClientFactory); + this.template = new StorageQueueTemplate(this.mockClientFactory); } @AfterEach @@ -108,32 +102,17 @@ public void close() throws Exception { @Test public void testReceiveFailure() { - when(this.mockClient.receiveMessages(eq(1), eq(Duration.ofSeconds(visibilityTimeoutInSeconds)))) + when(this.mockClient.receiveMessages(eq(1), any())) .thenReturn(new PagedFlux<>(() -> Mono.error(new QueueStorageException("error happened", null, null)))); - final Mono> mono = this.operation.receiveAsync(this.destination); + final Mono> mono = this.template.receiveAsync(this.destination, any()); verifyQueueStorageExceptionThrown(mono); } - @Test - public void testReceiveSuccessWithRecordMode() { - when(mockClient.deleteMessage(this.messageId, this.popReceipt)).thenReturn(Mono.empty()); - - final Mono> mono = this.operation.receiveAsync(destination); - assertTrue(Arrays.equals((byte[]) mono.block().getPayload(), this.queueMessage.getBody().toBytes())); - - verify(this.mockClient, times(1)).receiveMessages(1, - Duration.ofSeconds(visibilityTimeoutInSeconds)); - - Map headers = mono.block().getHeaders(); - assertNull(headers.get(AzureHeaders.CHECKPOINTER)); - } - @Test public void testReceiveSuccessWithManualMode() { when(mockClient.deleteMessage(this.messageId, this.popReceipt)).thenReturn(Mono.empty()); - operation.setCheckpointMode(CheckpointMode.MANUAL); - final Mono> mono = this.operation.receiveAsync(destination); + final Mono> mono = this.template.receiveAsync(destination, any()); Map headers = mono.block().getHeaders(); Checkpointer checkpointer = (Checkpointer) headers.get(AzureHeaders.CHECKPOINTER); @@ -143,13 +122,6 @@ public void testReceiveSuccessWithManualMode() { verify(this.mockClient, times(1)).deleteMessage(messageId, popReceipt); } - @Test - public void checkpointWithInvalidMode() { - assertThrows(IllegalStateException.class, () -> operation.setCheckpointMode(CheckpointMode.BATCH)); - assertThrows(IllegalStateException.class, () -> operation.setCheckpointMode(CheckpointMode.PARTITION_COUNT)); - assertThrows(IllegalStateException.class, () -> operation.setCheckpointMode(CheckpointMode.TIME)); - } - private void verifyQueueStorageExceptionThrown(Mono> mono) { try { mono.block(); diff --git a/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateSendTests.java b/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateSendTests.java index 099d3f696638b..a548d80bac317 100644 --- a/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateSendTests.java +++ b/sdk/spring/spring-messaging-azure-storage-queue/src/test/java/com/azure/spring/storage/queue/core/StorageQueueTemplateSendTests.java @@ -4,6 +4,7 @@ package com.azure.spring.storage.queue.core; import com.azure.spring.messaging.core.SendOperationTest; +import com.azure.spring.storage.queue.core.factory.StorageQueueClientFactory; import com.azure.storage.queue.QueueAsyncClient; import com.azure.storage.queue.models.SendMessageResult; import org.junit.jupiter.api.AfterEach; @@ -20,7 +21,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -public class StorageQueueTemplateSendTests extends SendOperationTest { +public class StorageQueueTemplateSendTests extends SendOperationTest { @Mock private StorageQueueClientFactory mockClientFactory; @@ -42,7 +43,7 @@ public void close() throws Exception { @BeforeEach public void setup() { - when(this.mockClientFactory.getOrCreateQueueClient(eq(destination))).thenReturn(mockClient); + when(this.mockClientFactory.createQueueClient(eq(destination))).thenReturn(mockClient); when(this.mockClient.sendMessage(anyString())).thenReturn(Mono.just(new SendMessageResult())); this.sendOperation = new StorageQueueTemplate(mockClientFactory); @@ -61,7 +62,7 @@ protected void verifySendCalled(int times) { @Override protected void verifyGetClientCreator(int times) { - verify(this.mockClientFactory, times(times)).getOrCreateQueueClient(this.destination); + verify(this.mockClientFactory, times(times)).createQueueClient(this.destination); } }