Spring 集成 - @Filter discardChannel and/or throwExceptionOnRejection 被忽略?

Spring Integration - @Filter discardChannel and/or throwExceptionOnRejection being ignored?

我有一个基于 java DSL 的 spring 集成 (spring-integration-java-dsl:1.0.1.RELEASE) 流程,它将消息通过 Filter 过滤掉某些消息。 Filter 组件在过滤掉不需要的消息方面工作正常。

现在,我想设置一个 discardChannel="discard.ch",但是,当我设置丢弃通道时,过滤掉的消息似乎从未真正到达指定的 discardChannel。知道为什么会这样吗?

我的@Filter注解了class/method:

@Component
public class MessageFilter {

    @Filter(discardChannel = "discard.ch")
    public boolean filter(String payload) {
        // force all messages to be discarded to test discardChannel
        return false;
    }

}

我的集成流程class:

@Configuration
@EnableIntegration
public class IntegrationConfig {

    @Autowired
    private MessageFilter messageFilter;

    @Bean(name = "discard.ch")
    public DirectChannel discardCh() {
        return new DirectChannel();
    }

    @Bean
    public IntegrationFlow inFlow() {

        return IntegrationFlows
        .from(Jms.messageDriverChannelAdapter(mlc)
        .filter("@messageFilter.filter('payload')")
        ...
        .get();
    }

    @Bean
    public IntegrationFlow discardFlow() {
        return IntegrationFlows
        .from("discard.ch")
        ...
        .get();
    }
}

我已经打开 spring 调试,但我看不到丢弃的消息实际去向。好像我在 @Filter 上设置的 discardChannel 根本没有被拾取。知道为什么会这样吗?

注释配置适用于使用基于注释的配置。

使用dsl时,注解不相关;您需要在 DSL 本身中配置 .filter...

.filter("@messageFilter.filter('payload')", e -> e.discardChannel(discardCh())