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

[pull] main from Azure:main #1102

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.azure.core.annotation.Fluent;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.DateTimeRfc1123;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
Expand Down Expand Up @@ -76,19 +77,19 @@ public final class FileShareProperties implements JsonSerializable<FileShareProp
* Returns the next allowed provisioned storage size downgrade time for the share. This property is only for file
* shares created under Files Provisioned v1 SSD and Files Provisioned v2 account type
*/
private OffsetDateTime nextAllowedQuotaDowngradeTime;
private DateTimeRfc1123 nextAllowedQuotaDowngradeTime;

/*
* Returns the next allowed provisioned IOPS downgrade time for the share. This property is only for file shares
* created under Files Provisioned v2 account type.
*/
private OffsetDateTime nextAllowedProvisionedIopsDowngradeTime;
private DateTimeRfc1123 nextAllowedProvisionedIopsDowngradeTime;

/*
* Returns the next allowed provisioned bandwidth downgrade time for the share. This property is only for file
* shares created under Files Provisioned v2 account type.
*/
private OffsetDateTime nextAllowedProvisionedBandwidthDowngradeTime;
private DateTimeRfc1123 nextAllowedProvisionedBandwidthDowngradeTime;

/*
* The authentication protocol that is used for the file share. Can only be specified when creating a share.
Expand Down Expand Up @@ -309,7 +310,10 @@ public Long maxBurstCreditsForIops() {
* @return the nextAllowedQuotaDowngradeTime value.
*/
public OffsetDateTime nextAllowedQuotaDowngradeTime() {
return this.nextAllowedQuotaDowngradeTime;
if (this.nextAllowedQuotaDowngradeTime == null) {
return null;
}
return this.nextAllowedQuotaDowngradeTime.getDateTime();
}

/**
Expand All @@ -319,7 +323,10 @@ public OffsetDateTime nextAllowedQuotaDowngradeTime() {
* @return the nextAllowedProvisionedIopsDowngradeTime value.
*/
public OffsetDateTime nextAllowedProvisionedIopsDowngradeTime() {
return this.nextAllowedProvisionedIopsDowngradeTime;
if (this.nextAllowedProvisionedIopsDowngradeTime == null) {
return null;
}
return this.nextAllowedProvisionedIopsDowngradeTime.getDateTime();
}

/**
Expand All @@ -330,7 +337,10 @@ public OffsetDateTime nextAllowedProvisionedIopsDowngradeTime() {
* @return the nextAllowedProvisionedBandwidthDowngradeTime value.
*/
public OffsetDateTime nextAllowedProvisionedBandwidthDowngradeTime() {
return this.nextAllowedProvisionedBandwidthDowngradeTime;
if (this.nextAllowedProvisionedBandwidthDowngradeTime == null) {
return null;
}
return this.nextAllowedProvisionedBandwidthDowngradeTime.getDateTime();
}

/**
Expand Down Expand Up @@ -606,14 +616,14 @@ public static FileShareProperties fromJson(JsonReader jsonReader) throws IOExcep
} else if ("maxBurstCreditsForIops".equals(fieldName)) {
deserializedFileShareProperties.maxBurstCreditsForIops = reader.getNullable(JsonReader::getLong);
} else if ("nextAllowedQuotaDowngradeTime".equals(fieldName)) {
deserializedFileShareProperties.nextAllowedQuotaDowngradeTime = reader
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
deserializedFileShareProperties.nextAllowedQuotaDowngradeTime
= reader.getNullable(nonNullReader -> new DateTimeRfc1123(nonNullReader.getString()));
} else if ("nextAllowedProvisionedIopsDowngradeTime".equals(fieldName)) {
deserializedFileShareProperties.nextAllowedProvisionedIopsDowngradeTime = reader
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
deserializedFileShareProperties.nextAllowedProvisionedIopsDowngradeTime
= reader.getNullable(nonNullReader -> new DateTimeRfc1123(nonNullReader.getString()));
} else if ("nextAllowedProvisionedBandwidthDowngradeTime".equals(fieldName)) {
deserializedFileShareProperties.nextAllowedProvisionedBandwidthDowngradeTime = reader
.getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString()));
deserializedFileShareProperties.nextAllowedProvisionedBandwidthDowngradeTime
= reader.getNullable(nonNullReader -> new DateTimeRfc1123(nonNullReader.getString()));
} else if ("enabledProtocols".equals(fieldName)) {
deserializedFileShareProperties.enabledProtocols = EnabledProtocols.fromString(reader.getString());
} else if ("rootSquash".equals(fieldName)) {
Expand Down
6 changes: 6 additions & 0 deletions sdk/spring/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Release History
## 5.21.0-beta.1 (Unreleased)
### Spring Cloud Azure Autoconfigure
This section includes changes in `spring-cloud-azure-autoconfigure` module.

#### Bugs Fixed
- Custom `ObjectMapper` bean does not work for received messages. [#37796](https://github.com/Azure/azure-sdk-for-java/issues/37796).

## 5.20.0 (2025-02-12)
- This release is compatible with Spring Boot 3.4.0-3.4.2, 3.3.0-3.3.6, 3.2.0-3.2.12, 3.1.0-3.1.12, 3.0.0-3.0.13. (Note: 3.4.x (x>2), 3.3.y (y>6) and 3.2.z (z>12) should be supported, but they aren't tested with this release.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

package com.azure.spring.cloud.autoconfigure.implementation.messaging;

import com.azure.messaging.eventhubs.EventData;
import com.azure.messaging.servicebus.ServiceBusMessage;
import com.azure.messaging.servicebus.ServiceBusReceivedMessage;
import com.azure.spring.cloud.autoconfigure.implementation.eventhubs.AzureEventHubsMessagingAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.implementation.servicebus.AzureServiceBusMessagingAutoConfiguration;
import com.azure.spring.messaging.converter.AzureMessageConverter;
import com.azure.spring.messaging.eventhubs.core.EventHubsProcessorFactory;
import com.azure.spring.messaging.eventhubs.core.listener.EventHubsMessageListenerContainer;
import com.azure.spring.messaging.eventhubs.implementation.core.config.EventHubsMessageListenerContainerFactory;
Expand All @@ -14,6 +18,7 @@
import com.azure.spring.messaging.servicebus.core.ServiceBusProcessorFactory;
import com.azure.spring.messaging.servicebus.core.listener.ServiceBusMessageListenerContainer;
import com.azure.spring.messaging.servicebus.implementation.core.config.ServiceBusMessageListenerContainerFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
Expand Down Expand Up @@ -44,8 +49,11 @@ static class EventHubsConfiguration {
@Bean(name = "azureEventHubsListenerContainerFactory")
@ConditionalOnMissingBean(name = "azureEventHubsListenerContainerFactory")
public MessageListenerContainerFactory<? extends MessageListenerContainer> azureEventHubsListenerContainerFactory(
EventHubsProcessorFactory eventHubsProcessorFactory) {
return new EventHubsMessageListenerContainerFactory(eventHubsProcessorFactory);
EventHubsProcessorFactory eventHubsProcessorFactory,
ObjectProvider<AzureMessageConverter<EventData, EventData>> messageConverterProvider) {
EventHubsMessageListenerContainerFactory containerFactory = new EventHubsMessageListenerContainerFactory(eventHubsProcessorFactory);
messageConverterProvider.ifAvailable(containerFactory::setMessageConverter);
return containerFactory;
}

}
Expand All @@ -56,8 +64,11 @@ static class ServiceBusConfiguration {
@Bean(name = "azureServiceBusListenerContainerFactory")
@ConditionalOnMissingBean(name = "azureServiceBusListenerContainerFactory")
public MessageListenerContainerFactory<? extends MessageListenerContainer> azureServiceBusListenerContainerFactory(
ServiceBusProcessorFactory serviceBusProcessorFactory) {
return new ServiceBusMessageListenerContainerFactory(serviceBusProcessorFactory);
ServiceBusProcessorFactory serviceBusProcessorFactory,
ObjectProvider<AzureMessageConverter<ServiceBusReceivedMessage, ServiceBusMessage>> messageConverterProvider) {
ServiceBusMessageListenerContainerFactory containerFactory = new ServiceBusMessageListenerContainerFactory(serviceBusProcessorFactory);
messageConverterProvider.ifAvailable(containerFactory::setMessageConverter);
return containerFactory;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import com.azure.core.credential.TokenCredential;
import com.azure.messaging.servicebus.ServiceBusClientBuilder;
import com.azure.messaging.servicebus.ServiceBusMessage;
import com.azure.messaging.servicebus.ServiceBusReceivedMessage;
import com.azure.spring.cloud.autoconfigure.implementation.condition.ConditionalOnAnyProperty;
import com.azure.spring.cloud.autoconfigure.implementation.servicebus.properties.AzureServiceBusProperties;
import com.azure.spring.cloud.core.customizer.AzureServiceClientBuilderCustomizer;
Expand All @@ -13,6 +15,7 @@
import com.azure.spring.cloud.core.service.AzureServiceType;
import com.azure.spring.messaging.ConsumerIdentifier;
import com.azure.spring.messaging.PropertiesSupplier;
import com.azure.spring.messaging.converter.AzureMessageConverter;
import com.azure.spring.messaging.implementation.converter.ObjectMapperHolder;
import com.azure.spring.messaging.servicebus.core.DefaultServiceBusNamespaceProcessorFactory;
import com.azure.spring.messaging.servicebus.core.DefaultServiceBusNamespaceProducerFactory;
Expand Down Expand Up @@ -137,9 +140,9 @@ ServiceBusMessageConverter serviceBusMessageConverter(ObjectMapper objectMapper)
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(ServiceBusProducerFactory.class)
ServiceBusTemplate serviceBusTemplate(ServiceBusProducerFactory senderClientfactory,
ServiceBusMessageConverter messageConverter) {
ServiceBusTemplate serviceBusTemplate = new ServiceBusTemplate(senderClientfactory);
ServiceBusTemplate serviceBusTemplate(ServiceBusProducerFactory senderClientFactory,
AzureMessageConverter<ServiceBusReceivedMessage, ServiceBusMessage> messageConverter) {
ServiceBusTemplate serviceBusTemplate = new ServiceBusTemplate(senderClientFactory);
serviceBusTemplate.setMessageConverter(messageConverter);
return serviceBusTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.spring.cloud.autoconfigure.implementation.messaging;

import com.azure.spring.cloud.autoconfigure.implementation.eventhubs.AzureEventHubsMessagingAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.implementation.servicebus.AzureServiceBusMessagingAutoConfiguration;
import com.azure.spring.messaging.eventhubs.core.EventHubsProcessorFactory;
import com.azure.spring.messaging.eventhubs.core.listener.EventHubsMessageListenerContainer;
import com.azure.spring.messaging.eventhubs.implementation.core.config.EventHubsMessageListenerContainerFactory;
import com.azure.spring.messaging.eventhubs.implementation.support.converter.EventHubsMessageConverter;
import com.azure.spring.messaging.implementation.annotation.EnableAzureMessaging;
import com.azure.spring.messaging.servicebus.core.ServiceBusProcessorFactory;
import com.azure.spring.messaging.servicebus.core.listener.ServiceBusMessageListenerContainer;
import com.azure.spring.messaging.servicebus.implementation.core.config.ServiceBusMessageListenerContainerFactory;
import com.azure.spring.messaging.servicebus.implementation.support.converter.ServiceBusMessageConverter;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;

public class AzureMessagingListenerAutoConfigurationTests {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
AzureEventHubsMessagingAutoConfiguration.class,
AzureServiceBusMessagingAutoConfiguration.class,
AzureMessagingListenerAutoConfiguration.class));

@Test
void withoutEnableAzureMessagingShouldNotConfigure() {
this.contextRunner
.withClassLoader(new FilteredClassLoader(EnableAzureMessaging.class))
.run(context -> {
assertThat(context).doesNotHaveBean(AzureMessagingListenerAutoConfiguration.EventHubsConfiguration.class);
assertThat(context).doesNotHaveBean(AzureMessagingListenerAutoConfiguration.ServiceBusConfiguration.class);
});
}

@Test
void withoutEventHubsMessageListenerContainerShouldNotConfigure() {
this.contextRunner
.withClassLoader(new FilteredClassLoader(EventHubsMessageListenerContainer.class))
.run(context -> {
assertThat(context).doesNotHaveBean(AzureMessagingListenerAutoConfiguration.EventHubsConfiguration.class);
});
}

@Test
void withoutServiceBusMessageListenerContainerShouldNotConfigure() {
this.contextRunner
.withClassLoader(new FilteredClassLoader(ServiceBusMessageListenerContainer.class))
.run(context -> {
assertThat(context).doesNotHaveBean(AzureMessagingListenerAutoConfiguration.ServiceBusConfiguration.class);
});
}

@Test
void configureContainerFactories() {
this.contextRunner
.withBean(EventHubsMessageConverter.class, () -> mock(EventHubsMessageConverter.class))
.withBean(EventHubsProcessorFactory.class, () -> mock(EventHubsProcessorFactory.class))
.withBean(ServiceBusMessageConverter.class, () -> mock(ServiceBusMessageConverter.class))
.withBean(ServiceBusProcessorFactory.class, () -> mock(ServiceBusProcessorFactory.class))
.run(context -> {
assertThat(context).hasBean("azureEventHubsListenerContainerFactory");
assertThat(context).hasBean("azureServiceBusListenerContainerFactory");

EventHubsMessageConverter eventHubsMessageConverter = context.getBean(EventHubsMessageConverter.class);
EventHubsMessageListenerContainerFactory eventHubsContainerFactory = (EventHubsMessageListenerContainerFactory) context.getBean("azureEventHubsListenerContainerFactory");
assertSame(eventHubsMessageConverter, eventHubsContainerFactory.getMessageConverter());

ServiceBusMessageConverter messageConverter = context.getBean(ServiceBusMessageConverter.class);
ServiceBusMessageListenerContainerFactory serviceBusContainerFactory = (ServiceBusMessageListenerContainerFactory) context.getBean("azureServiceBusListenerContainerFactory");
assertSame(messageConverter, serviceBusContainerFactory.getMessageConverter());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/**
* Bean post-processor that registers methods annotated with {@link T}
* to be invoked by a Azure message listener container created under the cover
* to be invoked by an Azure message listener container created under the cover
* by a {@link MessageListenerContainerFactory}
* according to the attributes of the annotation.
*
Expand Down