您可以使用 bean 并将您想要保留的标题和属性存储在线程本地成员中。保留和恢复所有标头/属性的简单示例如下所示:
public class BeanToHoldHeadersAndProps {
ThreadLocal<Map<String,Object>> headers = new ThreadLocal<>();
ThreadLocal<Map<String,Object>> props = new ThreadLocal<>();
public void saveHeaders(Exchange exchange) {
headers.set(exchange.getIn().getHeaders());
props.set(exchange.getProperties());
}
public void restoreHeaders(Exchange exchange) {
exchange.getIn().setHeaders(headers.get());
exchange.getProperties().putAll(props.get());
}
}
路线:
<camel:route id="header_preserving_route">
<camel:from url="activemq:xyz" />
<camel:bean ref="headerPreserver" method="saveHeaders" />
<camel:to url="smpp:abc" />
<camel:bean ref="headerPreserver" method="restoreHeaders" />
<camel:to url="cxf:hij" />
</camel:route>
根据您的要求,您可能希望保留第三个元素,即交易所的附件。