Spring Integration DSL,PayloadTypeRouter,路由器不支持的返回类型[类java.lang.Class]

时间:2016-09-12 09:23:27

标签: spring-integration

我想将PayloadTypeRouter用作Spring Integration DSL的一部分,如下所示:

jmsFlowsUtils.jmsXmlInputFlow(queue, loggingChannel)
    .<Object, Class<?>>route(Object::getClass, incomingMsg -> incomingMsg
            .subFlowMapping(SomeClass.class.getName(), firstFlow -> firstFlow
                    .<SomeClass>handle(handler1::handle))
                    // and so on
            .subFlowMapping(AnotherClass.class.getName(), secondFlow -> secondFlow
                    .<AnotherClass>handle(handler2::handle)))
                    // and so on
    .get();

我将xml消息发送到队列后,SI抱怨

org.springframework.messaging.MessagingException: 
Dispatcher failed to deliver Message; 
nested exception is org.springframework.messaging.MessagingException: 
unsupported return type for router [class java.lang.Class]

知道应用哪种解决方法?

1 个答案:

答案 0 :(得分:2)

.<Object, String>route(p ->  p.getClass().toString(), incomingMsg -> incomingMsg

或者已经在Spring Integration 4.3.1中使用Spring Integration Java DSL 1.2。已将Class<?>作为路由密钥修复为https://jira.spring.io/browse/INT-4057

因此,您不需要使用.toString()进行课程。项目测试的样本:

@Bean
public IntegrationFlow payloadTypeRouteFlow() {
    return f -> f
            .<Object, Class<?>>route(Object::getClass, m -> m
                    .channelMapping(String.class, "stringsChannel")
                    .channelMapping(Integer.class, "integersChannel"));
}