哪个消息将发送到文件出站网关的回复频道?

发布于 2025-01-23 02:00:58 字数 1161 浏览 4 评论 0原文

我正在研究一个项目,将春季集成用作代理,将HTTP请求分配给相关服务并将答案发送给客户端。 传入的HTTP请求首先进行预处理,然后发送到 http出站网关。 在返回客户端的路上,HTTP响应首先使用文件出站网关

<!-- write the message payload to ./toto/ and forward it to the http channel -->
<int-file:outbound-gateway request-channel="outputFileChannel"
                           reply-channel="outputHttpChannel"
                           directory="./toto/"
                           filename-generator-expression="headers.file_name + '.json'"
                           mode="REPLACE"/>

<!-- process the message before returning it to the inbound reply channel -->
<int:chain input-channel="routingOutputHttpChannel"
           output-channel="inboundReplyChannel">
    ...
</int:chain>

文件出站网关说“编写文件后,它也将其发送到回复频道作为消息的有效载荷”。 我的理解是,文件 contents 是作为消息有效载荷发送的,但是从我实施的内容中,是作为有效负载发送的文件的名称。 此时,文件名与我无关。有没有办法直接发送文件内容? 如果没有,我该怎么办读取所编写的文件的内容?插入文件入口通道适配器(似乎有点冗余)?

此外,处理未编写的文件的正确方法是什么?我的猜测将抓住MessagedeliveryException ...

I'm working on a project where Spring Integration is used as a proxy to distribute HTTP requests to the relevant services and send back the answers to the client.
Incoming HTTP requests are first preprocessed and sent to an HTTP outbound gateway.
On its way back to the client, the HTTP response is first written to a file, using a file outbound gateway:

<!-- write the message payload to ./toto/ and forward it to the http channel -->
<int-file:outbound-gateway request-channel="outputFileChannel"
                           reply-channel="outputHttpChannel"
                           directory="./toto/"
                           filename-generator-expression="headers.file_name + '.json'"
                           mode="REPLACE"/>

<!-- process the message before returning it to the inbound reply channel -->
<int:chain input-channel="routingOutputHttpChannel"
           output-channel="inboundReplyChannel">
    ...
</int:chain>

The documentation for the file outbound gateway says that "after writing the file, it also sends it to the reply channel as the payload of a message".
My understanding was that the file contents was sent as the message payload, but from what I've implemented, it is the name of the file written that is sent as payload.
The filename is irrelevant to me at this point. Is there a way to directly send the file contents?
If not, what should I do the read the contents of the file that was written? Plug a file inbound channel adapter (seems a bit redundant)?

Moreover, what's the proper way to handle the file not being written (so as to forge a specific HTTP response)? My guess would be catching a MessageDeliveryException...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桜花祭 2025-01-30 02:00:58

fileWritingMessageHandler将书面java.io.file对象发送回输出频道。这不是这个网关责任,向您退还文件的内容。使用有效载荷中的文件,您可以使用filetobytearraytransformerfileToStRingTransFormer作为流程中的下一个端点来获取该文件的内容。请参阅&lt; int-file:file-to-string-transformer&gt;&lt-file:分别用于XML配置的XML配置的文件与文件与文件to-bytes-transformer&gt;

为了在该&lt; int-file中捕获一个例外:出站 - gateway&gt;并在失败中做点事,您可以使用&lt; request handler-handler-advice-advice-chain&gt;子元素并提供ExpressionValuatingRequestHandlerAdlerAdvice https://docs.spring.io/spring-integration/docs/current/current/referent/reference/html/html/messaging-messaging-endpoints.html#message-message-message handler-Advice-Advice-Chain < /a>

The FileWritingMessageHandler sends a written java.io.File object back to the output channel. This not this gateway responsibility to give you back a content of the file. With the File in the payload you can use a FileToByteArrayTransformer or FileToStringTransformer as the next endpoint in your flow to get a content of that file. See <int-file:file-to-string-transformer> or <int-file:file-to-bytes-transformer> for an XML configuration, respectively.

To catch an exception in that <int-file:outbound-gateway> and do something with the failure, you can use a <request-handler-advice-chain> sub-element and provide an ExpressionEvaluatingRequestHandlerAdvice: https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#message-handler-advice-chain

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文