【问题标题】:Spring data stream, FTP source custom headersSpring数据流,FTP源自定义headers
【发布时间】:2019-02-14 19:40:06
【问题描述】:

场景:

  • 我正在使用 spring data starter 应用程序来创建 FTP 源。

代码:

@SpringBootApplication
@Import({ FtpSourceConfiguration.class, AWSLocalStackConfig.class })
public class FtpSourceKinesisApplication {

  public static void main(String[] args) {
    SpringApplication.run(FtpSourceKinesisApplication.class, args);
  }
}
  • FtpSourceConfiguration 是来自FTP Starter 的标准配置,AWSLocalStackConfig 仅用于在 localstack 上使用 Kinesis binder


待办事项:

  • 我想在每条消息上添加一个自定义标头,例如“source:ProviderA”、“source:ProviderB”
  • 我将有多个 FTP 源将消息推送到同一主题。
  • 我想识别消息源,而无需创建中间主题来丰富标头。

有没有办法在不自己创建 IntegrationFlow 的情况下做到这一点?

【问题讨论】:

    标签: spring-cloud-stream spring-cloud-dataflow


    【解决方案1】:

    @SylvainM 具有讽刺意味的是,我们目前正在努力为我们所有的应用程序初学者提供此类支持。我的意思是您现在可以通过简单地将通道拦截器添加到您的 Sopurce 的输出通道来完成它,但是管道中的内容将更加简单并且基于 Spring Cloud Functions。 留意有关此的博客。

    【讨论】:

    • 感谢您提供的信息,我创建了一个 GlobalChannelInterceptor 我没有找到如何通过代码附加拦截器。
    • SourceHeaderInterceptor(Source source) { ((ChannelInterceptorAware) source.output()).addInterceptor(this); }
    【解决方案2】:

    根据 Oleg 的评论,这就是我所做的:

    @Component
    public class SourceHeaderEnricher implements ChannelInterceptor {
    
      SourceHeaderEnricher (Source source) {
        ((ChannelInterceptorAware) source.output()).addInterceptor(this);
      }
    
      @Override
      public Message<?> preSend(Message<?> message, MessageChannel channel) {
        MessageBuilder<?> builder = MessageBuilder.fromMessage(message);
        builder.setHeader("x-custom", "hello world");
        return builder.build();
      }
    }
    

    如果您正在实现自己的应用程序,这是可行的。要使用裸启动应用程序来完成,显然我们需要等待下一个版本。

    【讨论】:

      猜你喜欢
      • 2013-08-15
      • 2011-12-24
      • 2018-05-16
      • 1970-01-01
      • 2018-11-27
      • 2015-12-15
      • 2018-02-01
      • 1970-01-01
      • 2018-03-15
      相关资源
      最近更新 更多