Spring Integration 路由器在 XML 配置中指定如下:
<int:chain id="integrationFrontDoorQueueChain" input-channel="integrationFrontDoorQueueChannel">
<int:transformer ref="integrationJsonPayloadTransformer" method="transformMessagePayload"/>
<int:service-activator ref="firstScanInventoryService" method="sendMessage"/>
<int:router ref="integrationRouterImpl" method="route" default-output-channel="nullChannel"/>
</int:chain>
在 IntegrationRouterImpl 的 Java 代码中,我们找到了 channel 列表。
@Component("integrationRouterImpl")
public class IntegrationRouterImpl {
private final IntegrationReferenceDataLoader integrationReferenceDataLoader;
@Autowired
public IntegrationRouterImpl(IntegrationReferenceDataLoader integrationReferenceDataLoader) {
this.integrationReferenceDataLoader = integrationReferenceDataLoader;
}
public List<String> route(IntegrationPayload integrationPayload) {
final List<String> channelList = new ArrayList<String>();
for (Long productId : integrationPayload.getProductIds()) {
final Set<String> channels = integrationReferenceDataLoader.findChannelsForProduct(productId, integrationPayload.getAction().name());
if (channels != null) {
channelList.addAll(channels);
}
}
return channelList;
}
}
看起来,如果 channelList
中的第一个 channel 根本没有配置,那么第二个 channel 也不会被调用。有一个异常(exception):
[org.springframework.integration.support.channel.ChannelResolutionException: failed to look up MessageChannel bean with name 'seaActivationChannel'.
但是,我没有找到捕获此异常并移至下一个 channel 的方法
路由器中离开方法路由后的堆栈流程如下:
2015-12-18 15:06:30,297 [SimpleAsyncTaskExecutor-1] DEBUG org.springframework.integration.handler.LoggingHandler:67 - (inner bean)#8 received message: [Payload=org.springframework.integration.MessagingException: failed to resolve channel name 'seaActivationChannel'][Headers={timestamp=1450469190297, id=60c2f22b-55a0-4512-7d5c-f798ef67c8ca}]
2015-12-18 15:06:30,299 [SimpleAsyncTaskExecutor-1] ERROR org.springframework.integration.handler.LoggingHandler:140 - org.springframework.integration.MessagingException: failed to resolve channel name 'seaActivationChannel'
at org.springframework.integration.router.AbstractMappingMessageRouter.resolveChannelForName(AbstractMappingMessageRouter.java:168)
at org.springframework.integration.router.AbstractMappingMessageRouter.addChannelFromString(AbstractMappingMessageRouter.java:197)
at org.springframework.integration.router.AbstractMappingMessageRouter.addToCollection(AbstractMappingMessageRouter.java:218)
……………
Caused by: org.springframework.integration.support.channel.ChannelResolutionException: failed to look up MessageChannel bean with name 'seaActivationChannel'
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveChannelName(BeanFactoryChannelResolver.java:102)
at org.springframework.integration.router.AbstractMappingMessageRouter.resolveChannelForName(AbstractMappingMessageRouter.java:164)
... 74 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'seaActivationChannel' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:568)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1102)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:278)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveChannelName(BeanFactoryChannelResolver.java:93)
最佳答案
首先看起来您使用的是 Spring Integration 3.0.x 或更高版本。 ChannelResolutionException
已从 Spring Integration 4.0 更改为 DestinationResolutionException
。虽然没关系。
不知道为什么你没见过,但是<router>
支持您需要的选项:
<xsd:attribute name="resolution-required">
<xsd:annotation>
<xsd:documentation>
Specify whether channel names must always be successfully resolved
to existing channel instances.
If set to 'true', a MessagingException will be raised in case
the channel cannot be resolved. Setting this attribute to 'false',
will cause any unresovable channels to be ignored.
If not explicitly set, 'resolution-required' will
default to 'true'.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="xsd:boolean xsd:string" />
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
关于java - 如何忽略 Spring Integration 路由器中的 Channel ResolutionException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34362614/