简体   繁体   English

Spring Cloud Stream Apps-在步骤之间传递信息

[英]Spring Cloud Stream Apps - Passing information between steps

Can anyone suggest me ways to pass metadata between steps of SCDF pipe? 谁能建议我在SCDF管道步骤之间传递元数据的方法? 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. 我希望有一种在Rabbit或kafka消息头中发送此类详细信息的方法。

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): 如果您的处理程序方法返回POJO,则该框架将通过复制某些标头等从其创建消息。但是,在您的情况下,如果您想控制消息中包含的所有内容(包括标头),则只需定义处理程序方法即可返回消息(见下文):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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