在我的例子中,应用程序接收mqtt消息,并根据消息中的类型值将它们路由到某个通道。这样,我定义了一个IntegrationFlow
来路由消息,如下所示:
@Bean
public IntegrationFlow mqttInbound() {
return IntegrationFlows.from(inbound())
.transform(new PojoTransformer())
.<Data, String>route(Data::getType,
m -> m.prefix("Channel."))
.get();
}
此外,我还定义了一些其他的IntegrationFlow
来处理这些通道中的消息,例如
@Bean
public IntegrationFlow normalProcess() {
return IntegrationFlows.from("Channel.1")
.handle("normalHandler", "handle")
.channel("mqttOutboundChannel")
.get();
}
问题是,如果没有定义的映射(例如类型是"4"),就会出现一个类似org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'Channel.4' in the BeanFactory
的异常。我的问题是,如何将所有这些未映射的消息路由到某个错误通道,然后进行一些异常处理。
发布于 2019-08-06 23:29:50
将resolutionRequired
设置为false并添加默认输出通道。
.<Data, String>route(Data::getType,
m -> m.prefix("Channel.")
.resolutionRequired(false)
.defaultOutputChannel("noRouteChannel"))
https://stackoverflow.com/questions/57378579
复制相似问题