javaspring-cloudspring-cloud-stream

How to intercept Spring Cloud Stream messages?


Spring allows interception of messages for many of their products, like RestTemplate and SpringMVC. Is it possible to intercept Spring Cloud Stream messages? For both incoming and outgoing messages.


Solution

  • Not sure what you mean by interception here - both examples you give are not message-based :).

    But you want to get access to the full message, you can use that as argument to a @StreamListener or @ServiceActivator-annotated method. Also, Spring Cloud Stream allows you to set up a full Spring Integration pipeline, so you can add advices and everything you need - see here: https://github.com/spring-projects/spring-integration-java-dsl/wiki/Spring-Integration-Java-DSL-Reference.

    I would encourage you to take a look at the Spring Integration reference as well http://docs.spring.io/autorepo/docs/spring-integration/4.2.6.RELEASE/reference/html/. Spring Cloud Stream injects the channels automatically, and from there you have full freedom on how you construct your pipeline.

    Hope this helps, Marius