【发布时间】:2014-12-15 11:40:19
【问题描述】:
我们有一个案例,在我们的 Spring 集成拆分器逻辑中,它可以返回一个空的 ArrayList,因此不提供要路由的数据。当拆分器返回一个空的ArrayList 时,我们应该如何处理这种情况并将其重新路由到不同的通道。
更新:
如 Artem 所示,我创建了一个自定义建议并成功完成了重新路由,但是仍然存在两个问题,其中第二个描述的是列出的阻止程序问题
我目前的班级如下
public class EmptyListRequestHandlerAdvice extends AbstractRequestHandlerAdvice {
private final MessagingTemplate messagingTemplate = new MessagingTemplate();
public EmptyListRequestHandlerAdvice(MessageChannel emptyListChannel) {
this.messagingTemplate.setDefaultChannel(emptyListChannel);
}
@Override
protected Object doInvoke(ExecutionCallback callback, Object target,
Message<?> message) throws Exception {
Object result = callback.execute();
if (result==null) {
this.messagingTemplate.convertAndSend(new ArrayList<InventoryHotel>());
}
return result;
}
每当拆分器返回一个新的空数组列表时,“callback.execute() 的结果为空。但是,只要从拆分器返回的数组列表不为空,返回的结果就是 org.springframework.integration.util 类型。 FunctionIterator 而不是集合类型。关于是否有可能在两种情况下都返回集合而不是 null 或函数迭代器?至少避免获取函数迭代器并获取数组列表。
此外,当为构造函数设置有效的通道名称并通过该通道向转换器方法发送消息时,转换器方法成功执行,但是当它返回值时会发生以下错误
org.springframework.messaging.MessagingException: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
at org.springframework.integration.dispatcher.AbstractDispatcher.wrapExceptionIfNecessary(AbstractDispatcher.java:133)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:120)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255)
关于为什么会发生这种情况以及如何解决它的任何建议。
问候, 米琳达
【问题讨论】:
标签: java spring arraylist spring-integration enterprise-integration