This is the second blog in a series of pre-release blogs in preparation for Spring Cloud Stream 2.0.0.RELEASE.
Spring Cloud Stream 2.0 introduces polled consumers, where the application can control message processing rates.
Spring Cloud Stream has the concepts of producers and consumers; when using the messaging paradigm, MessageChannels are bound to destinations (e.g. Kafka topics, Rabbit Exchanges/Queues). To-date, on the consumer side, messages are delivered whenever an idle consumer is available. In effect, the broker controls the rate of delivery; usually, the next message is delivered immediately after the current one is processed.
2.0 introduces polled consumers, where the application can control the rate of message consumption.
Polled consumers are supported by the Kafka and RabbitMQ binders.
The message is not acknowledged until the handler’s handleRequest method exits.
The MessageHandler is the interface from spring-messaging; you can provide one of the standard Spring Integration message handlers, or your own implementation (often a lambda). Because the handleMessage method takes a Message<?> argument, there is no type information and the payload will not be converted.
The following simple Spring Boot application provides a complete example; it receives String payloads, converts them to upper case and forwards the result to another destination.
Applications can now control the rate at which messages are consumed.
For more information, see Using Polled Consumers in the reference manual.