The Spring Blog

Engineering
Releases
News and Events

Spring Cloud Function 2.0 and Azure Functions

Spring Cloud Function has had support for Microsoft Azure Functions since version 1.0, but in the latest 2.0 releases (still in milestone phase) we decided to change the programming model a bit. This article describes what the changes mean for users, and provides a bit of background behind the shift. We in the Spring team had a lot of fun working on this and collaborating with the folks at Microsoft to get the best blend of the two technologies for our users.

Azure Functions for Java

Microsoft has had Java support in Azure Functions for a while, and it enables developers to easily write and deploy Java code that connects in a serverless way to a wide range of platform services (events, databases, storage, HTTP gateways, etc.) in Azure. It comes with an annotation-based programming model that puts the function implementations in Java methods. So you write a method and annotation it with @FunctionName, and it becomes an Azure Function. There is a rich set of tools based on a Maven plugin (currently) that drives the Azure command line and can be used to build a function, run and debug it locally and deploy it to the cloud. There is a Quickstart Guide on the Azure website which will help you get all the pre-requisites installed and working, and there is more detailed documentation about how Azure Functions works in the Developer’s Guide.

The annotations also tie the function method parameters and return types to the services used at deployment time. For example, if you want to bind to an HTTP gateway at deployment time you use @HttpTrigger:

@FunctionName("uppercase")
public Bar execute(
    @HttpTrigger(name = "req", methods = { HttpMethod.GET, HttpMethod.POST },
        authLevel = AuthorizationLevel.ANONYMOUS) Foo foo,
    ExecutionContext context) {
  return new Bar(foo.getValue());
}

In this example we accept an incoming HTTP POST request and Azure binds its body to a POJO of type Foo. We transform the Foo into a Bar and it comes back to the caller in the HTTP response.

HTTP triggers are in the top 5 most popular integrations in Azure Functions, but even more popular are the event-based and storage or database-based triggers. The complete list can be found in the Triggers and Bindings documentation - there is a table where you can click on a specific binding or trigger and it will take you to reference page where there are code samples in all languages, including Java.

Here’s another example using the Azure Event Hub as an input and Cosmos DB as an output. This example is in github:

@FunctionName("uppercase")
public Bar execute(
  @EventHubTrigger(name = "data", eventHubName = "events",
        connection = "TRANSACTIONS_EVENT_HUB_CONNECTION_STRING")
    Foo data,
    @CosmosDBOutput(name = "document", databaseName = "inventory",
        collectionName = "messages",
        connectionStringSetting = "PRODUCT_ITEMS_DOCUMENTDB_CONNECTION_STRING",
        createIfNotExists = true)
    OutputBinding<Bar> document,
    final ExecutionContext context) {
  return document.setValue(new Bar(foo.getValue()));
}
Note
If the incoming JSON cannot be converted to the function input type (Foo in this case) you will see Azure fail with a confusing no such method error. If you see that you might be able to change the @FunctionName method to a String input and eyeball the data to make sure it is bindable to the desired input type.

The annotations carry connection credential information through an indirection to environment variables that are configured in the function deployment. The configuration for all that happens in the build pom.xml through the Azure Functions Maven plugin. For example:

<plugin>
  <groupId>com.microsoft.azure</groupId>
  <artifactId>azure-functions-maven-plugin</artifactId>
  <configuration>
    <resourceGroup>${functionResourceGroup}</resourceGroup>
    <appName>${functionAppName}</appName>
    <region>${functionAppRegion}</region>
    <appSettings>
            <property>
              <name>FUNCTIONS_EXTENSION_VERSION</name>
              <value>beta</value>
            </property>
            <property>
              <name>TRANSACTIONS_EVENT_HUB_CONNECTION_STRING</name>
            <value>${TRANSACTIONS_EVENT_HUB_CONNECTION_STRING}</value>
            </property>
            <property>
              <name>PRODUCT_ITEMS_DOCUMENTDB_CONNECTION_STRING</name>
              <value>${PRODUCT_ITEMS_DOCUMENTDB_CONNECTION_STRING}</value>
            </property>
            <property>
              <name>MSDEPLOY_RENAME_LOCKED_FILES</name>
              <value>1</value>
            </property>
    </appSettings>
  </configuration>
  <executions>
    <execution>
            <id>package-functions</id>
            <goals>
              <goal>package</goal>
            </goals>
    </execution>
  </executions>
</plugin>

In this case the environment variable names link the plugin configuration to the function binding declaration. For instance the @EventHubTrigger has a connection attribute that will be popeulated at runtime from the TRANSACTIONS_EVENT_HUB_CONNECTION_STRING environment variable. The plugin configures it remotely using a local environment variable with the same name (notice the ${} placeholders), which the developer or CI process is responsible for setting up at runtime.

Your own personal connection strings are secrets and can be found in the Azure Dashboard - when you click on the relevant resource there is usually a Connection Strings link (or similar) that you can copy and paste to your local process (e.g. in a script that you run locally but do not check into source control). E.g. you might use a setup-env.sh script like this:

export PRODUCT_ITEMS_DOCUMENTDB_CONNECTION_STRING="AccountEndpoint=https://..."
export TRANSACTIONS_EVENT_HUB_CONNECTION_STRING="Endpoint=sb://..."

and source it once at the beginning of a terminal session.

There are some other plugin declarations in the pom.xml of the sample. They are all important but basically boilerplate - you should be able to copy them and re-use the same configuration in all Azure Function Applications.

Read more...

Spring Tools 4 GA released

spring tools 4

After a decade of rolling out updates and improvements to the famous Spring Tool Suite and the Spring IDE components for Eclipse, a new era of Spring tooling starts today and we welcome you to the all-new Spring Tools 4. After an intensive period of public betas, we are happy to announce the first official release today.

Spring Tools 4 is a completely new set of tools for working with Spring projects in your favorite IDEs and editors. They are re-built from scratch with the goal in mind to provide the best support for implementing enterprise-grade applications based on Spring and Spring Boot across development environments and lightweight editors. They provide a unique editor-centric experience for working with Spring projects, ranging from smart and Spring-aware content-assist to a unique new way of connecting your source code with and enriching it with detailed information and insights from your running Spring Boot applications. This puts your source code editor side-by-side with your running boot applications.

Read more...

Spring Boot 2.1 M4 available now

On behalf of the team and everyone that contributed, I am happy to announce that the fourth milestone of Spring Boot 2.1 has been released and is available from our milestone repository. This release closes over 40 issues and pull requests.

This milestone ships with the latest Spring Framework 5.1 which went GA last week.

Along with the Spring Framework update, this release also includes a bunch of other dependency version updates.

For a complete list of changes and upgrade instructions, please see the Spring Boot 2.1 Release Notes on the wiki and the updated reference documentation.

Read more...

Hands on with Spring Vault 2.1

Spring Vault 2.1 is already in sight. I would like to use this post to take a deeper look at the changes and features that are in the upcoming release.

The team has been working on a whole bunch of new features:

  • Extending infrastructure-based authentication to support Google Cloud IAM and Azure Managed Service Identity

  • Integrating Vault’s versioned Key-Value backend

  • Wrapping API support

  • Java 11 compatibility

Spring Vault supports HashiCorp Vault versions 0.5 up to 0.11. You can find the Spring Vault and Spring Cloud Vault examples repository on GitHub. Now, let’s dive into the Spring Vault 2.1 features!

Read more...

Spring Integration, AMQP and Kafka Release Candidates Available

On behalf of Spring Integration team I’m pleased to announce Release Candidates for the Spring Messaging projects. Each is based on the recently released Spring Framework 5.1 GA, has upgraded dependencies and will be part of the upcoming Spring Boot 2.1 M4 - just in time for Spring One Platform!

The artifacts for these projects are available in the Spring Milestone repository.

Please, refer to the What’s New chapter in each Reference Manual for more information about new features and notable changers for each project mentioned below.

Read more...

Spring Session BOM Bean-RC1 Released

This post was authored by Vedran Pavić

On behalf of the community, I’m pleased to announce the release of Spring Session BOM Bean-RC1. This release is based on Spring Session 2.1.0.RC1 which resolves a total of 13 issues. Please read on for the highlights of the release.

Support for Java 11

Spring Session now supports Java 11, while the required version of course stays at Java 8. Our CI pipeline has been enhanced so that the project is now continuously verified against Java 8, 10 and 11.

Dependency Upgrades

Spring Session 2.1.0.RC1 builds on the following latest and greatest releases of key dependencies:

  • Spring Framework 5.1.0.RELEASE

  • Spring Data Lovelace-RELEASE

  • Spring Security 5.1.0.RELEASE

  • Project Reactor Californium-RELEASE

  • Hazelcast 3.10.5

Read more...

Spring Data JDBC, References, and Aggregates

In my previous blog article, I described how to set up and use Spring Data JDBC. I also described the premise of making Spring Data JDBC easier to understand than JPA. This becomes interesting once you consider references. As a first example, consider the following domain model:

class PurchaseOrder {

  private @Id Long id;
  private String shippingAddress;
  private Set<OrderItem> items = new HashSet<>();

  void addItem(int quantity, String product) {
    items.add(createOrderItem(quantity, product));
  }

  private OrderItem createOrderItem(int quantity, String product) {

    OrderItem item = new OrderItem();
    item.product = product;
    item.quantity = quantity;
    return item;
  }
}
Read more...

Spring Boot for Apache Geode & Pivotal GemFire 1.0.0.M3 Released!

On behalf of the Spring and Apache Geode communities, I am pleased to announce the third milestone release of Spring Boot for Apache Geode & Pivotal GemFire (SBDG), version 1.0.0.M3.

The bits for 1.0 final GA are nearly complete. There will be 1 more development milestone (RC1) before final GA. The new 1.0.0.M3 bits can be acquired from the Spring libs-milestone repo.

What’s New

SBDG 1.0.0.M3 adds support for using Spring Boot’s Actuator feature with Apache Geode & Pivotal GemFire (and, by extension, Pivotal Cloud Cache, which is backed by Pivotal GemFire).

Read more...

Spring Data Lovelace GA released

On behalf of the Spring Data team, it’s my pleasure to announce the general availability of Spring Data Lovelace. This release train ships on top of the just-released Spring Framework 5.1 GA. You can easily consume Spring Data Lovelace with next week’s Spring Boot 2.1 M4 release. Spring Data Lovelace ships with a number of major features, improvements, and bugfixes. The most notable topics are:

  • Support for immutable objects
  • Deferred JPA repository initialization
  • Support for MongoDB 4.0 Client Sessions and Transactions
  • New Spring Data JDBC module
  • Apache Cassandra mapping improvements for Map and tuple types, Lifecycle Callbacks, and Kotlin Extensions
  • Replica Reads with Spring Data Redis
Read more...

Spring Framework 5.1 goes GA

Dear Spring community,

It is my pleasure to announce that Spring Framework 5.1 is generally available from repo.spring.io as well as Maven Central now! Check out our recently updated docs…

Spring Framework 5.1 requires JDK 8 or higher and specifically supports JDK 11 as the next long-term support release. It comes with initial refinements for GraalVM compatibility and deeply integrates with the recently released Reactor Californium and Hibernate ORM 5.3.

Read more...