Search code examples
javaspring-integrationspring-integration-dsl

Is there a way to write a filter in spring-integration using java annotation?


I'm trying to convert xml configuration in spring-integration, and I encountered a filter that goes like:

<
  int:filter
  expression="someFilterExpression"
  input-channel="inputChannel"
  output-channel="outputChannel"
  discard-channel="discardChannel"
/>

Is there a way to come up with a Java annotation equivalent for this? I've tried to use the @Filter annotation, but it didn't include the expression field in there.


Solution

  • thanks for pointing me to the right direction. To elaborate further on what I did. I put in the spring integration dsl dependency

    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-java-dsl</artifactId>
      <version>1.2.3.RELEASE</version>
    </dependency>
    

    and used the IntegrationFlows to build the filter. I did it by:

    @Bean
    public IntegrationFlow filter() {
        return IntegrationFlows
            .from("someInputChannel")
            .filter(
                "someFilterExpression",
                e -> e.discardChannel("someDiscardChannel"))
            .channel("someOutputChannel")
            .get();
    }
    

    So, the above Java DSL is basically the same as:

    <
      int:filter
      expression="someFilterExpression"
      input-channel="someInputChannel"
      output-channel="someOutputChannel"
      discard-channel="someDiscardChannel"
    />
    

    Thank you very much again for your answer. :)