【发布时间】:2018-11-23 10:14:10
【问题描述】:
我的程序在高层执行以下操作
Task 1
get the data from the System X
the Java DSL split
post the data to the System Y
post the reply data to the X
the Java DSL aggregate
Task 2
get the data from the System X
the Java DSL split
post the data to the System Y
post the reply data to the X
the Java DSL aggregate
...
问题是当一个post the data to the System Y子任务失败时,错误信息被正确地发送回系统X,但之后任何其他子任务或任务都没有执行。
我的错误处理程序是这样做的:
...
Message<String> newMessage = MessageBuilder.withPayload("error occurred")
.copyHeadersIfAbsent(message.getPayload().getFailedMessage().getHeaders()).build();
...
Set some extra headers etc.
...
return newMessage;
可能是什么问题?
编辑:
我调试了 Spring 集成。在错误情况下,只有第一条错误消息到达方法AbstractCorrelatingMessageHandler.handleMessageInternal。其他成功和失败消息不会出现在该方法中。
如果没有错误,则所有消息都到达该方法,最后释放组。
我的程序有什么问题?
编辑 2:
这是有效的:
为Http.outboundGateway 添加了advice:
.handle(Http.outboundGateway(...,
c -> c.advice(myAdvice()))
还有myAdvice bean
@Bean
private Advice myAdvice() {
return new MyAdvice();
}
还有MyAdvice 类
public class MyAdvice<T> extends AbstractRequestHandlerAdvice {
@SuppressWarnings("unchecked")
@Override
protected Object doInvoke(final ExecutionCallback callback, final Object target, final Message<?> message)
throws Exception {
...
try {
result = (MessageBuilder<T>) callback.execute();
} catch (final MessageHandlingException e) {
take the exception cause for the new payload
}
return new message with the old headers and replyChannel header and result.payload or the exception cause as a payload
}
}
【问题讨论】:
-
编辑了原帖。
标签: spring-integration spring-integration-dsl