The Spring Blog

Engineering
Releases
News and Events

Spring Cloud Stream - functional and reactive

In the previous post, I tried to provide justification for our shift to a functional programming model in Spring Cloud Stream (SCSt). It’s less code, less configuration. Most importantly, though, your code is completely decoupled and independent from the internals of SCSt.

In this post, I’ll dig a little deeper and summarize the core features of our functional support, specifically around its reactive features.

IMPORTANT: Anything you can do with @StreamListener/@EnableBinding you can also do without it. In other words, the functional support is now feature-compatible with the annotation-based support.

Read more...

Simple Event Driven Microservices with Spring Cloud Stream

Event driven architecture is great. But without a framework, writing the scaffolding required to work with popular event messaging platforms can be messy. In this post we’ll take a look at how Spring Cloud Stream can be used to simplify your code.

The Problem

You just want to write logic for your event driven application, but the boilerplate messaging code can get in the way. Connecting your apps to messaging services is tricky, and if you’re an enterprise developer, you probably need to work with multiple messaging technologies (either on-premises or in the cloud).

Read more...

This Week in Spring - October 14th, 2019

Hi, Spring fans! WHEW! What a week! Last week was the insane SpringOne Platform 2019 event, from which I am still recovering! Then I flew home, hosted Spring team member and Micrometer lead and friend Tommy Ludwig in San Francisco, and prepared to fly out for meetings and user group appearances on Monday (in Stuttgart, Germany) and Tuesday (in Amsterdam).

I prepared, and got into the Uber going to San Francisco airport when I got a call from my brother saying my 81-year-old dad wasn’t doing well (thanks to everyone for the well-wishes!) and was rushed to the hospital. I had to, regretfully, cancel my live appearances in those countries. I am SO sorry for those I disappointed. I was very happy to be able to do a few of those meetings remotely. Thanks to everyone who indulged me and supported me as I flew to Los Angeles to be with my father.

Read more...

Spring Cloud Stream - demystified and simplified

This is the first post in a series of blog posts meant to clarify and preview what’s coming in the upcoming releases of spring-cloud-stream and spring-cloud-function (both 3.0.0).

Recently, I had a discussion with a user and heard something that prompted me to begin a series of blog posts (starting with this one) with the goal of both demystifying the true goals of Spring Cloud Stream and Spring Cloud Function projects as well as demonstrating their new features.

Spring Integration Wrapper?

The specific phrase that prompted all this was - "Spring Cloud Stream, being a light Spring Integration input/output router…”. That’s an interesting perception, but I have to disagree. While it may have been inspired by Enterprise Integration Patterns (EIP) and builds on top of Spring Integration (SI), that last part is really just an implementation detail. Spring Cloud Stream (SCSt) as a framework was never about “being a light Spring Integration input/output router”. In fact, this statement shows part of the problem, where SI (the framework of choice to support some of the internal requirements of SCSt) was somehow perceived to be the core of SCSt in such way that many perceive SCSt to be an extension or a wrapper to SI. It is not. It has always been about pure microservices and binding them to sources and targets of data (i.e., messaging systems) . Simple as that.
If you abstract yourself far enough from knowing the internals of SCSt, you quickly realize that it is really a binding and activation framework. It binds a piece of code (provided by the user) to source/target of data exposed by the binder and activates such code according to binder implementation (for example, message arrival and so on). That is pretty much it.

Read more...

This Week in Spring (SpringOne Platform 2019 edition) - October 8th, 2019

It’s here it’s finally here! My favorite time of the year! Happy SpringOne Platform week! This week I’m in amazing Austin, TX talking to anybody who wants to about all things Spring. There have been a ton of amazing things announced at this show but one thing I’ve been excited to share with y’all is that we just announced the new Azure Spring Cloud runtime. (More on that in the links below)

I’ve been busy! I’m doing one talk with Microsoft on Azure Spring Cloud, and another with Okta / Google on simplifying the dev lifecycle. Also, I’m hosting the keynote tomorrow morning. So much to do, so little time!

Read more...

What's new in Spring Data Moore?

Spring Data Moore ships with 16 modules and over 700 tickets completed. It includes tons of improvements and new features across the portfolio and has a strong focus on three major topics: Reactive, Kotlin, and Performance. The release adds features such as declarative reactive transactions and Coroutines/Flow support and comes with up to 60%* faster finder methods.

Let’s start with a look at some of the Reactive features of Moore.

Declarative, reactive transactions

The Lovelace Release introduced early support for reactive transactions in a closure-fashioned style that left some room for improvements. The following listing shows that style:

Reactive Transactions in Lovelace (with MongoDB)
public Mono<Process> doSomething(Long id) {

  return template.inTransaction().execute(txTemplate -> {

    return txTemplate.findById(id)
      .flatMap(it -> start(txTemplate, it))
      .flatMap(it -> verify(it))
      .flatMap(it -> finish(txTemplate, it));

  }).next();
}

In the preceding snippet, the transaction has to be initiated by explicitly calling inTransaction() with a transaction-aware template within the closure, calling next() at the end to turn the returned Flux into a Mono to satisfy the method signature, even though findById(…) already emits only a single element.

Obviously, this is not the most intuitive way of doing reactive transactions. So let’s have a look at the same flow using declarative reactive transaction support. As with Spring’s transaction support, you need a component to handle the transaction for you. For reactive transactions, a ReactiveTransactionManager is currently provided by the MongoDB and R2DBC modules. The following listing shows such a component:

@EnableTransactionManagement
class Config extends AbstractReactiveMongoConfiguration {

  // …

  @Bean
  ReactiveTransactionManager mgr(ReactiveMongoDatabaseFactory f) {
    return new ReactiveMongoTransactionManager(f);
  }
}

From there, you can annotate methods with @Transactional and rely on the infrastructure to start, commit, and roll back transactional flows to handle the lifecycle via the Reactor Context. This lets you turn the code from Lovelace into the following listing, removing the need for the closure with its scoped template and the superfluous Flux to Mono transformation:

Declarative Reactive Transactions in Moore (with MongoDB)
@Transactional
public Mono<Process> doSomething(Long id) {

  return template.findById(id)
    .flatMap(it -> start(template, it))
    .flatMap(it -> verify(it))
    .flatMap(it -> finish(template, it));
}
Read more...

Reactor Dysprosium (3.3.x) goes GA

Hello Reactor community,

On behalf of the Reactor team and its heroic new contributors, I am delighted to announce that Reactor Dysprosium can now be found on your preferred Maven repositories, like this one.

It is the fourth release train since Reactor Core 3.x and it includes Reactor Core 3.3, Reactor Netty 0.9 and a newcomer, Reactor Pool 0.1. Check out the major change logs and release notes:
- reactor-core 3.3.0.RELEASE
- reactor-netty 0.9.0.RELEASE
- reactor-pool 0.1.0.RELEASE

Reactor Dysprosium modules still require JDK 8 or higher. They come with many performance improvements and we even have identified more areas to focus on the next patches and major releases. Please join me in giving a warm welcome to a new module to the family, Reactor Pool. It is the generic embeddable reactive object pool you were waiting for. It is used by Reactor Netty and we plan to build more features on top of it. As with Reactor Netty, we haven’t qualified a major “1.x” release as we expect tweaks before considering it API stable.

Read more...

Reactor Californium-SR12 is out

The 12th Service Release for Californium is out. As per tradition, it fixes several issues and bring improvements all around.

The release is available on your preferred maven central repository.

Change logs and release notes:
- reactor-core 3.2.12.RELEASE
- reactor-netty 0.8.12.RELEASE

Bismuth EOL

With Dysprosium-RELEASE, our reactor-core 3.1.x and reactor-netty 0.7.x lines will not receive further patches. We encourage our users to update to Californium releases trains, which match Spring Boot 2.1.x and Spring Framework 5.1.x.

Read more...