Java 我可以从入站通道适配器处理程序中发送消息Spring集成通道吗?
如果某些条件合适,我希望从我的文件入站通道适配器的处理程序中向另一个通道发送消息。有时入站文件的值超出规范,我希望将文件发送到错误目录,但不中断入站到出站的流程,因为即使超出规范的文件也需要转到辅助位置 我的配置示例:Java 我可以从入站通道适配器处理程序中发送消息Spring集成通道吗?,java,spring,spring-integration,Java,Spring,Spring Integration,如果某些条件合适,我希望从我的文件入站通道适配器的处理程序中向另一个通道发送消息。有时入站文件的值超出规范,我希望将文件发送到错误目录,但不中断入站到出站的流程,因为即使超出规范的文件也需要转到辅助位置 我的配置示例: <int-file:inbound-channel-adapter id="filesIn" directory="${input.path}"
<int-file:inbound-channel-adapter id="filesIn"
directory="${input.path}"
filename-regex="\\d{8}-\\d+\\.txt">
<int:poller id="poller" fixed-rate="500"/>
</int-file:inbound-channel-adapter>
<int-file:file-to-string-transformer input-channel="filesIn"
output-channel="strings"
delete-files="true" />
<int:channel id="strings"/>
<int:channel id="errorChannel" />
<int:exception-type-router input-channel="strings"
default-output-channel="output">
<int:mapping exception-type="ca.uhn.hl7v2.HL7Exception"
channel="errorChannel"/>
</int:exception-type-router>
<int:service-activator input-channel="output"
output-channel="archive"
ref="handler" method="handleString"/>
<int:service-activator input-channel="errorChannel"
output-channel="errorOutput"
ref="handler" method="handleError" />
<int-file:outbound-channel-adapter id="archive"
directory="${archive.path}"
delete-source-files="true"/>
<int-file:outbound-channel-adapter id="errorOutput"
directory="${hl7.error.path}"/>
<bean id="handler" class="com.giotta.service.Hl7MessageConsumer"/>
从术语的角度来看,入站适配器没有“处理程序”。根据类型,它们可以是消息源,也可以是消息生产者 也就是说,您可以在入站适配器之后立即添加路由器,并根据您想要的标准路由到不同的通道 编辑
尝试将字符串解析为HL7消息时,在Hl7MessageConsumer中引发异常 但你现在有 …>转换器->etr->处理程序-> i、 e.etr在处理程序之前 你需要像
<int-file:inbound-channel-adapter id="filesIn"
directory="${input.path}"
filename-regex="\\d{8}-\\d+\\.txt">
<int:poller id="poller" fixed-rate="500" error-channel="errorChannel" />
</int-file:inbound-channel-adapter>
<int-file:file-to-string-transformer input-channel="filesIn"
output-channel="strings"
delete-files="true" />
<int:channel id="strings"/>
<int:service-activator input-channel="strings"
output-channel="archive"
ref="handler" method="handleString"/>
<int-file:outbound-channel-adapter id="archive"
directory="${archive.path}"
delete-source-files="true"/>
<int:channel id="errorChannel" />
<int:service-activator input-channel="errorChannel"
output-channel="errorOutput"
ref="handler" method="handleError" />
<int-file:outbound-channel-adapter id="errorOutput"
directory="${hl7.error.path}"/>
<bean id="handler" class="com.giotta.service.Hl7MessageConsumer"/>
我已经使用了异常类型路由器,但我仍然希望原始入站文件继续到出站,如果发生错误,还希望返回错误通道。我似乎想不出怎样才能让这两个都去。也有一个或另一个。有什么提示吗?我的意思是你可以使用自定义路由器来检查文件,并根据你的验收标准路由到一个或另一个通道。现在还不清楚使用异常类型路由器是什么意思,还没有异常。也许,如果您编辑您的问题以显示您尝试过的一些配置,它可能会帮助我们更好地理解您的意思。我已经添加了我的配置。异常类型路由器在这里毫无意义-负载是字符串,而不是异常。如果您想使用一些特殊条件来决定字符串是否应转到错误或输出,则需要使用自定义路由器。谁抛出了一个
HL7Exception
?当试图将字符串解析为HL7消息时,该异常在Hl7MessageConsumer中抛出。
<int:publish-subscribe-channel id="errorChannel" />
<int:service-activator input-channel="errorChannel"
output-channel="errorOutput"
ref="handler" method="handleError" />
<int:transformer input-channel="errorChannel"
output-channel="archive" expression="payload.failedMessage" />