【问题标题】:how to use router in spring integration?如何在 Spring 集成中使用路由器?
【发布时间】:2015-06-30 02:35:14
【问题描述】:

我在Spring Integration项目中使用router,我想根据自定义表达式路由消息,为此我定义了一个路由器和两个路由消息通道,我的路由器代码是:

<int:router input-channel="toSplitter"
                default-output-channel="aggregateResultsChannel"
                expression="@util.determine(payload)"
            >
        <int:mapping value="true" channel="mvChannel" />
        <int:mapping value="false" channel="toGet" />
    </int:router>

在我的 bean 中:

public class util {
    public static boolean determine(List<FileInfo> path) {
        for(FileInfo fileInfo:path) {
             evaluate(fileInfo);
         }
         return;//how to return here...
    }  
}

问题是我想评估每个路径对象并将每个消息路由到不同的通道,例如 list 包含 {file1,file2} ,那么在评估file1 route to mvChannel 和file2 route toGet chennel 之后怎么做呢?

【问题讨论】:

    标签: spring ftp spring-integration


    【解决方案1】:

    即使没有任何&lt;mapping&gt;,也可以配置&lt;router&gt;。在这种情况下,route function 必须返回 MessageChannel bean 名称。

    例如:


    public class util {
        public static String determine(List<FileInfo> path) {
            return evaluate(path) ? "mvChannel" : "toGet";
        }  
    }
    

    【讨论】:

    • 感谢@Artem 的回复并编辑我的帖子:) ,我想路由path 列表中的每一项,例如:for(FileInfo fileInfo:path) { // how do it here }
    • 对于Collection payload,您必须在&lt;router&gt; 之前使用&lt;splitter&gt;。每个 EIP 组件只负责其目标,仅此而已。灵活一点,尽量遵循loosely-coupling的原则。请首先阅读enterpriseintegrationpatterns.com
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 2018-06-15
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多