Announcing Spring Cloud Azure 4.9.0 and 5.3.0: Now Generally Available
Published Jul 06 2023 06:52 PM 3,196 Views
Microsoft

We're thrilled to announce the general availability of Spring Cloud Azure 4.9.0 and 5.3.0. These major releases bring increased compatibility with Spring Boot 2 for 4.9.0 and Spring Boot 3 for 5.3.0.

 

Highlighted Features and Improvements

 

Spring Cloud Azure 5.3.0

 

This release includes noteworthy features and enhancements such as:

  • Spring Data Cosmos and Spring Data Cosmos Starter, are now compatible with Spring Boot 3.
  • Compatibility with Spring Boot 3.1.
  • Introduction of a new Spring Boot starter for Azure Event Grid.
  • Passwordless connection support for Azure Service Bus JMS.
  • Upgrades to azure-sdk-bom (version 1.2.14) and azure-resourcemanager (version 2.28.0).

Spring Cloud Azure 4.9.0

 

This version comes with the following additions:

  • A new Spring Boot starter for Azure Event Grid.
  • Upgrades to azure-sdk-bom (version 1.2.14) and azure-resourcemanager (version 2.28.0).

Moreover, we've launched the 4.9.0-beta.1 version of spring-cloud-azure-starter-openai, extending support to the Azure OpenAI service.

Let's delve deeper into the new offerings!

 

What's New?

 

Spring Data Cosmos

 

Spring Data Cosmos 5.3.0 is the first GA version compatible with Spring Boot 3. For more details, refer to the Spring Data Cosmos changelog.

There's no change in how you use Spring Data Cosmos; just add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-cosmos</artifactId>
</dependency>

Next, configure the Cosmos properties in your application.properties:

spring.cloud.azure.cosmos.endpoint=<your-azure-cosmos-endpoint>
spring.cloud.azure.cosmos.database=<your-azure-cosmos-database>

 

NOTE: This configuration will use the available credential on your local environment, such as Azure CLI, to connect to the Cosmos database. For configuring other types of authentication principals, refer to Authenticate with Azure Active Directory.

You can define a repository in your project to save and query data as follows:

 

@Repository
public interface UserRepository extends CosmosRepository<User, String> {}

@Service
public class CosmosService {

    @Autowired
    private UserRepository userRepository;

    public void someMethod() {
        User testUser = new User(USER_ID, "testFirstName", "testLastName", "test address line one");
        userRepository.save(testUser);
        Optional<User> user = userRepository.findById(USER_ID);
        userRepository.delete(testUser);
    }
}

 

Autoconfiguration of Azure Event Grid

 

Azure Event Grid enables easy construction of event-based architecture applications. With the new Spring Cloud Azure starter for Event Grid, Event Grid client autoconfiguration is a breeze. For more information about Azure Event Grid, visit What is Event Grid?.

 

To utilize this feature, add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-eventgrid</artifactId>
</dependency>

Then, configure the Event Grid properties in your application.properties:

spring.cloud.azure.eventgrid.endpoint=https://xxx.eventgrid.azure.net/api/events
spring.cloud.azure.eventgrid.key=<your-event-grid-key>

NOTE: You can also use Azure Active Directory principals to connect to the Event Grid service. Authenticate with Azure Active Directory offers guidance on configuring other types of authentication principals.

Here's how you can autowire the Event Grid client:

@Autowired
EventGridPublisherClient<EventGridEvent> client;

public void someMethod(String user) {
    // ...
    EventGridEvent event = new EventGridEvent("A user is created", "User.Created.Object", 
    BinaryData.fromObject(user), "0.1"); // topic must be set when sending to an Event Grid Domain.
    client.sendEvent(event);
    // ...
}

 

Passwordless Connection to Azure Service Bus JMS

 

Prior to the support of passwordless connections, connection to Azure Service Bus required a service bus connection string. However, with the new feature, you can connect to Azure Service Bus JMS using Managed Identity or any Azure Active Directory principal. Check out https://aka.ms/passwordless-connections to learn more about passwordless connections.

To use passwordless connection to connect to Azure Service Bus JMS, add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
</dependency>

Then, configure the necessary properties in application.properties:

spring.jms.servicebus.passwordless-enabled=true
spring.jms.servicebus.namespace=<your-servicebus-namespace>
spring.jms.servicebus.pricing-tier=<your-servicebus-pricing-tier> # e.g. standard
spring.cloud.azure.credential.managed-identity-enabled=true

NOTE: This configuration will use the system-assigned managed identity to connect to the Service Bus. Refer to Authenticate with Azure Active Directory for configuring other types of authentication principals.

Afterward, you can use the Spring JmsTemplate or @JmsListener in your application:

@SpringBootApplication
@EnableJms
public class ServiceBusJMSApplication implements CommandLineRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(ServiceBusJMSApplication.class);
    private static final String QUEUE_NAME = "<QueueName>";

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        SpringApplication.run(ServiceBusJMSApplication.class, args);
    }

    @Override
    public void run(String... args) {
        LOGGER.info("Sending message");
        jmsTemplate.convertAndSend(QUEUE_NAME, "Hello Word");
    }

    @JmsListener(destination = QUEUE_NAME, containerFactory = "jmsListenerContainerFactory")
    public void receiveMessage(String message) {
        LOGGER.info("Message received: {}", message);
    }
}



Azure OpenAI Support

 

Azure OpenAI is a managed service enabling developers to deploy, tune, and generate content from OpenAI models on Azure resources.

The Spring Cloud Azure starter for Azure OpenAI allows autoconfiguration of the OpenAI client (provided by Azure Java SDK). To use this feature, add the starter to your project:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-openai</artifactId>
  <version>4.9.0-beta.1</version>
</dependency>

Next, configure the OpenAI properties in your application.properties:

spring.cloud.azure.openai.endpoint=https://xxx.openai.azure.com/
spring.cloud.azure.openai.key=<your-azure-openai-key>
# or you can use the key of the public non-Azure OpenAI
# spring.cloud.azure.openai.non-azure-openai-key=<your-public-openai-key>

Then, you are ready to autowire the OpenAI client:

@Autowired
private OpenAIClient client;

public void someMethod() {
    List<String> prompt = List.of("How many breeds of dogs are there in the world?");

    Completions completions = client.getCompletions("gpt-35-turbo", new CompletionsOptions(prompt));

    for (Choice choice : completions.getChoices()) {
        System.out.printf("Index: %d, Text: %s.%n", choice.getIndex(), choice.getText());
    }
}

 

One Dependency BOM for All Spring Cloud Azure Components

 

All Spring Cloud Azure components, including Cosmos and App Configuration, are managed by the spring-cloud-azure-dependencies BOM. You can add the BOM to your project as follows:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.azure.spring</groupId>
      <artifactId>spring-cloud-azure-dependencies</artifactId>
      <version>5.3.0</version> <!-- 4.9.0 or 4.9.0-beta.1 -->
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

This allows all Spring Cloud Azure component versions to be managed. For example:

<dependency>
  <groupId>com.azure.spring</groupId>
  <artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
  <!-- The version can be omitted -->
</dependency>

 

Compatibility with Spring Boot 3.1

 

Spring Cloud Azure 5.3.0 is now compatible with Spring Boot 3.1. This version is compatible with both Spring Boot 3.0.x and 3.1.x. Check https://aka.ms/spring/versions for more information on versioning details.

 

Feedback

 

Your feedback and contributions are always welcome. Please reach out to us on StackOverflow or GitHub.

 

Resources

 

To learn more about Spring Cloud Azure, we invite you to visit the following links:

Co-Authors
Version history
Last update:
‎Jul 06 2023 06:52 PM
Updated by: