【发布时间】:2020-04-05 09:43:16
【问题描述】:
我有一个由 REST 控制器调用的消息网关,我想知道处理下游流中可能发生的任何错误的正确方法是什么。
我所说的“处理任何错误”是指记录一些关于它们的信息,采取一些其他可能的操作,最后能够向控制器返回 400。
对我来说,更有意义的方法是在网关上有一个 errorChannel,但我认为 replyChannel 也可能有意义。
我已经能够使用“errorChannel”方法处理错误,不知道这是不是要走的路:
@MessagingGateway(errorChannel = "integrationFlowErrorChannel")
public interface OrderGateway {
@Gateway(requestChannel = "orders.input")
void processOrderRequest(Order order);
}
发送到 errorChannel 的任何错误都由以下服务激活器处理:
@ServiceActivator(inputChannel="integrationFlowErrorChannel")
public void handleExceptions(Message<MessageHandlingException> message) throws RuntimeException {
log.error(String.format("error: %s", message));
log.error(String.format("error: %s", message.getPayload()));
throw new RuntimeException("something bad happened");
}
谢谢
【问题讨论】: