【发布时间】:2017-09-15 07:04:45
【问题描述】:
我有以下消息处理链。
<int:header-enricher input-channel="acceptFileChannel" output-channel="validateMessageChannel">
<int:error-channel ref="validateSplitTransformErrorChannel"/>
<int:header name="originalFileName" expression="payload.getName()"/>
<int:header name="originalFile" expression="payload"/>
</int:header-enricher>
<int:service-activator input-channel="validateMessageChannel" output-channel="splitMessageChannel">
<bean class="com.my.usual.ValidationService">
<property name="schemaResource" value="classpath:/META-INF/xsd/locals_final_version.xsd"/>
</bean>
</int:service-activator>
<int:splitter id="staxXmlSplitter" input-channel="splitMessageChannel"
output-channel="payloadTypeRoutingChannel">
<bean class="com.my.usual.XMLSplitter"/>
</int:splitter>
<int:payload-type-router input-channel="payloadTypeRoutingChannel">
<int:mapping type="org.w3c.dom.Node" channel="afterSplitChannel"/>
<int:mapping type="com.my.usual.SequenceSizeMessage" channel="barrier"/>
</int:payload-type-router>
<int:channel id="afterSplitChannel">
<int:dispatcher task-executor="taskExecutor"/>
</int:channel>
<si-xml:xpath-router id="afterSplitRouter" input-channel="afterSplitChannel" evaluate-as-string="true">
<si-xml:xpath-expression expression="local-name(/Act | /Partner)"/>
<si-xml:mapping value="Act" channel="transformActChannel"/>
<!--todo: for example of extending-->
<si-xml:mapping value="Partner" channel="nullChannel"/>
</si-xml:xpath-router>
在这个链中,我设置了两个消息头:originalFileName 和 originalFile。
似乎在com.my.usual.XMLSplitter 拆分消息后保留标题的最简单方法是覆盖方法之类的。
@Override
protected boolean shouldCopyRequestHeaders() {
return true;
}
但是,如果我在拆分消息中只需要一个标头怎么办?我以某种方式注意到originalFileName 的读取值并将其写入每个拆分的消息。
我想我可以通过willAddHeaders 和addHeaders 的拆分器方法编写标题。但我不确定拆分器 bean 的范围。那么如果它是一个单例并且将是用户并发,如何保留原始标题?
有人可以帮我找到好的解决方案吗?
感谢您的回答。
【问题讨论】: