![](/img/trans.png)
[英]How to send message to the rabbitmq queue using spring integration java DSL
[英]How to send error message once a http call takes more time than is required in Spring integration dsl?
这里我有三个子流,其中一个是 HTTP 出站调用。 我希望 HTTP 调用应该尝试在提到的时间之前得到响应。 如果超时,则主流程应该中断,并且它应该以 Json 格式显示错误消息作为输出。
下面是代码 -
@Bean
public IntegrationFlow flow() {
return flow ->
flow.handle(validatorService, "validateRequest")
.split()
.channel(c -> c.executor(Executors.newCachedThreadPool()))
.scatterGather(
scatterer ->
scatterer
.applySequence(true)
.recipientFlow(flow1())
.recipientFlow(
f ->
f.gateway(
flow2(), gateway -> gateway.replyTimeout(3000L)))
.recipientFlow(flow3()),
gatherer ->
gatherer
.releaseLockBeforeSend(true)
.releaseStrategy(group -> group.size() == 2))
.aggregate(someMethod1())
.to(someMethod2());
}
请参阅消息传递网关中的错误处理文档: https ://docs.spring.io/spring-integration/docs/current/reference/html/messaging-endpoints.html#gateway-no-response。
考虑在网关定义上添加一个errorChannel()
以及该replyTimeout()
以构建您想要的错误回复。 但是,您也可以考虑为用于该 HTTP 调用的RestTemplate
添加请求超时之类的内容,以防止长时间等待 HTTP 响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.