2. What’s New in 2.0?

Spring Cloud Stream introduces quite a number of new features, enhancements and changes. The following sections outline most notable ones.

2.1 New Features and Components

2.1.1 Polling Consumer

Introduction of polled consumers, where the application can control message processing rates. Please refer to the appropriate section for more details. You can also read this blog for more details spring.io/blog/2018/02/27/spring-cloud-stream-2-0-polled-consumers

2.1.2 Micrometer support

Metrics has been switched to use Micrometer. MeterRegistry is also provided as a bean so custom application can autowire it to capture custom metrics. Please refer to the appropriate section for more details

2.1.3 New Actuator Binding controls

There are now new new Actuator binding controls to both visualize as well as control Bindings lifecycle. For more details please visit Section 6.6, “Binding visualization and control”

2.1.4 Configurable RetryTemplate

Aside from providing properties to configure RetryTemplate we now allow you to provide your own effectively overriding the one provided by the framework. Simply configure it as a @Bean in your application.

2.2 Notable changes and enhancements

2.2.1 Both Actuator and Web dependencies are now optional

This helps to slim down the footprint of the deployed application in the event neither of the functionality is required. It also allows one to swicth between the reactive and conventional web paradigms by adding one of the following dependencies manually:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
</dependency>

or

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

Actuator dependency can be added as follows:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2.2.2 Content-type negotiation improvenents

One of the core themes for 2.0 is improvements (both consistency and performance) around content-type negotiation and message conversion. The following summary outlines notable changes and improvements. Please refer to the appropriate section for more details as well as this blog spring.io/blog/2018/02/26/spring-cloud-stream-2-0-content-type-negotiation-and-transformation.

  • All message conversion is now handled only by MessageConverters.
  • Introduction of @StreamMessageConverter annotation to provide custom MessageConverters.
  • Introduction of the default Content Type as application/json which needs to be taken into consideration when migrating 1.3 application and/or operating in the mixed mode (i.e., 1.3 producer → 2.0 consumer).
  • Messages with textual payloads and contentType text/…​ or …​/json are no longer converted to Message<String> for cases where argument type of the provided MessageHandler can not be determnied (i.e., public void handle(Message<?> message) or public void handle(Object payload)). Further more, a strong argument type may not be enough to properly convert messages, so contentType header is may be used as supplement by some MessageConverters.

2.3 Notable Deprecations

2.3.1 Java serialization (Java native and Kryo)

  • JavaSerializationMessageConverter and KryoMessageConverter. While these two converters remain for now, they will be moved out of the core packages and support in the future. The main reason for this deprecation is to signal the issue type-based language-specific serialization couuld cause in the distributed environments, where Producers and Consumers may not only depend on different JVM versions or have different versions of supporting libraries (i.e., Kryo), but to also draw the attention to the fact that Consumers and Producers may and in a lot of cases are non-Java based.

2.3.2 Deprecated classes and methods

Following is a quick summary of notable deprecations. See corresponding javadocs fort more details.

  • SharedChannelRegistry in favor of SharedBindingTargetRegistry.
  • Bindings - beans qualified by it are already uniquely identified by their type. For example, provided Source, Processor or custom bindings:
public interface Foo {
	String OUTPUT = "fooOutput";

	@Output(Foo.OUTPUT)
	MessageChannel output();
}
  • HeaderMode.raw. Use none, headers or embeddedHeaders
  • ProducerProperties.partitionKeyExtractorClass in favor of partitionKeyExtractorName and ProducerProperties.partitionSelectorClass in favor of partitionSelectorName. This is to ensure that both components are Spring configured/managed and referenced in Spring-friendly way.
  • BinderAwareRouterBeanPostProcessor - while the component exists it is no longer a Bean Post Processor and will be renamed in the future.
  • BinderProperties.setEnvironment(Properties environment) in favor of BinderProperties.setEnvironment(Map<String, Object> environment).

This section goes into more detail about how you can work with Spring Cloud Stream. It covers topics such as creating and running stream applications.