简体   繁体   中英

Spring Cloud Stream Apps - Passing information between steps

Can anyone suggest me ways to pass metadata between steps of SCDF pipe? Here are some of the use cases I'm trying to address:

  1. The file details such as name, directory, size, etc are passed on to next step when using 'file' source.
  2. I want some metadata created in a process step be passed on to the following step. (This metadata is separate from the payload)

I'm hoping that there is a way of sending such details in the rabbit or kafka message headers.

You can/should certainly utilize Message headers. Remember you control he return value of the handler method. If your handler method returns POJO, then the framework will create a Message from it copying certain headers etc. However, in your case if you want to control everything that goes into the Message (including headers) all you need is to define handler method that returns Message (see below):

@StreamListener(..)
@SendTo(..)
public Message<?> handle(String str) {
  . . .
  return MessageBuilder.withPayload(..).setHeader(..).setHeader(..).build();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM