2

I have a java DSL based spring integration (spring-integration-java-dsl:1.0.1.RELEASE) flow which puts messages through a Filter to filter out certain messages. The Filter component works okay in terms of filtering out unwanted messages.

Now, I would like to set either a discardChannel="discard.ch" but, when I set the discard channel, the filtered out messages never seem to actually go to the specified discardChannel. Any ideas why this might be?

My @Filter annotated 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;
    }

}

My Integration Flow 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();
    }
}

I have turned on spring debugging on and, I can't see where discarded messages are actually going. It is as though the discardChannel I have set on the @Filter is not being picked up at all. Any ideas why this might be?

Going Bananas
  • 2,265
  • 3
  • 43
  • 83

1 Answers1

2

The annotation configuration is for when using annotation-based configuration.

When using the dsl, the annotation is not relevant; you need to configure the .filter within the DSL itself...

.filter("@messageFilter.filter('payload')", e -> e.discardChannel(discardCh())
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • 1
    Hello Gary, I've configured the discard channel in the DSL code itself as you have suggested and that worked okay. I always seem to get confused between Spring java based annotation configurations and Spring java DSL configurations. Thanks for your help! – Going Bananas Jun 05 '15 at 14:02