首页 > 解决方案 > 是否可以在路由器中的消息中添加标头?

问题描述

我有返回通道名称的路由器(如预期的那样):

public String route(Message<CustomEntity> msg) {
    ...        
    return "toAdd";
    ...
    return "toUpd";
    ...
}

是否可以在路由器中为消息添加新标头?

标签: javaspringspring-integration

解决方案


不,这不对。这不是改变消息的路由器责任。您需要HeaderEnricher改用:https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-transformation-chapter.html#header-enricher

标头可以由 SpEL 填充或Function在运行时针对请求消息填充。


推荐阅读