我是 Spring 和 Spring 集成的新手,我决定全力以赴 - 现在,我陷入了困境。
考虑以下 Spring 配置 - 一个将请求发送到 AMQP 代理进行处理的入站网关:
<int:channel id="requestChannel" />
<int:channel id="responseChannel"/>
<int:channel id="myDiscardChannel"/>
<int-http:inbound-gateway id="myInboundGateway"
request-channel="requestChannel"
reply-channel="responseChannel"
mapped-request-headers="*"
mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
path="/foo"
reply-timeout="50000"/>
<int:chain input-channel="requestChannel" output-channel="responseChannel">
<int:filter expression="someExpression" discard-channel="myDiscardChannel" />
<int-amqp:outbound-gateway amqp-template="amqpTemplate" exchange-name-expression="fooexchange" reply-timeout="50000" />
</int:chain>
我希望能够做的是,当人为的“someExpression”表达式对表示 HTTP 请求的消息求值为 false 时,使用适当的 HTTP 状态代码和有效负载完成原始请求。
我研究了几种方法:
1)设置过滤器来生成异常,并在错误 channel 上处理它们,但我似乎无法正确理解这一点 - 很难找到这种技术的正确示例。
2)设置过滤器以将丢弃的消息发送到丢弃 channel - 我尚未弄清楚如何生成消息并将其发送回入站网关以完成原始请求。
任何帮助将不胜感激!
最佳答案
只需将转换器订阅到丢弃 channel 即可;省略转换器上的输出 channel ,转换结果将返回入站网关。
您可以从入站网关和链(输出 channel )中删除responseChannel
(回复 channel );在这种情况下不需要它。
关于java - 过滤消息的 HTTP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19062117/