简体   繁体   English

我可以从入站通道适配器处理程序中向Spring Integration Channel消息吗?

[英]Can I Message Spring Integration Channel from within My Inbound Channel Adapter Handler?

I'm looking to message another channel, if certain conditions merit, from within the handler of my file inbound-channel-adapter. 我希望在某些情况下从我的文件inbound-channel-adapter的处理程序中向另一个频道发送消息。 Sometimes the inbound file has out of specification values and I'd like to send the file to an error directory, but not interrupt the flow of the inbound to outbound since even the out of specification file still needs to goto a secondary location. 有时入站文件的值超出规范,我想将文件发送到错误目录,但不中断入站到出站的流程,因为即使超出规范的文件仍然需要转到辅助位置。

Example of my configuration: 我的配置示例:

<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"/>

粗图

From a terminology perspective, inbound adapters don't have "handlers". 从术语的角度来看,入站适配器没有“处理程序”。 Depending on the type, they are either message sources or message producers. 根据类型,它们是消息源或消息生产者。

That said, you can add a router immediately after the inbound adapter and route to different channels based on whatever criteria you want. 也就是说,您可以在入站适配器之后立即添加路由器,并根据所需条件将其路由到其他通道。

EDIT 编辑

The exception is thrown within the Hl7MessageConsumer while trying to parse the String into a HL7 message 尝试将String解析为HL7消息时,在Hl7MessageConsumer中引发了异常

But you currently have 但是你目前有

...>transformer->etr->handler->... ......>变压器 - > etr->处理 - > ...

ie the etr is before the handler. 即etr 处理程序之前

You need something like... 您需要类似...

<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"/>

ie the poller catches the exception and routes an ErrorMessage to the error channel. 即,轮询器捕获异常并将ErrorMessage路由到错误通道。 The error message payload is a MessagingException with two properties ( cause and failedMessage ). 错误消息有效负载是具有两个属性( causefailedMessage )的MessagingException

EDIT2 EDIT2

I still want the string to goto the "archive" adapter in addition to the "errorOutput" adapter. 除了“ errorOutput”适配器之外,我仍然希望该字符串转到“归档”适配器。

In that case... 在这种情况下...

<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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM