带路由的 Spring Integration Java DSL 过滤器

问题描述 投票:0回答:0

此处为 Spring Integration 5.x(Java DSL)。我有兴趣在我的

IntegrationFlow
中实现一个过滤器,它具有以下逻辑:

  • 如果入站消息的标题为“fruit”,那么我希望将其路由到“fruit-channel”(无论 fruit 标题的值如何)
  • 否则我希望将消息发送到丢弃通道/死信队列

我对过滤器本身的最佳尝试:

public class FruitFilter {

    @Filter
    public boolean fruitsOnly(Message<?> message) {
        return message.getHeaders().containsKey("fruit");
    }

}

我在流程中使用此过滤器的最佳尝试:

@Bean
public IntegrationFlow fruitFlow() {

    return IntegrationFlows.from(ingressChannel())

        .filter(fruitFilter)

        // TODO #1: how to route messages (containing the fruit header) on to the "fruit-channel"?
        // TODO #2: how to process messages that were filtered and sent to the discard/DLQ channel?
        .get();

}

我认为 Java 代码和 Spring Integration 的 API 的使用在上面是可以的,但我不明白我在哪里/如何放置实际的基于过滤器的routing。任何人都可以发现我在这里出错的地方吗?提前致谢!

java spring-integration
© www.soinside.com 2019 - 2024. All rights reserved.