简体   繁体   English

Spring Integration-如何使用SpEL在注释基础上过滤消息?

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

I read the xml based configuration on Spring Integration reference page: 我在Spring Integration参考页面上阅读了基于xml的配置:

<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. 这样我就可以将SpEL用作过滤消息的逻辑。

Thanks. 谢谢。

You can either use the Java DSL... 您可以使用Java DSL ...

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

or configure it with beans... 或使用bean配置它...

@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 ...");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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