简体   繁体   中英

Spring Integration - How to use SpEL to filter message on an annotation base?

I read the xml based configuration on Spring Integration reference page:

<filter expression="#jsonPath(payload,'$..book[2].isbn') matches '\d-\d{3}-\d{5}-\d'"/>

What is the annotation based equivalence of this? So that I can use SpEL as the logic to filter messages.

Thanks.

You can either use the Java DSL...

@Bean
public IntegrationFlow filteringFlow() {
    return IntegrationFlows.from("someChannel")
            .filter("#jsonPath(...) matches ...")
            .channel("outChannel")
            .get();
}

or configure it with beans...

@Bean
@ServiceActivator(inputChannel = "someChannel")
public MessageHandler filter() {
    MessageFilter filter = new MessageFilter(selector());
    filter.setOutputChannelName("outChannel");
    return filter;
}

@Bean
public MessageSelector selector() {
    return new ExpressionEvaluatingSelector("#jsonPath(...) matches ...");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM