Patrik Mihalčin
Patrik Mihalčin

Reputation: 4031

Spring Integration DSL, PayloadTypeRouter, unsupported return type for router [class java.lang.Class]

I'd like to use PayloadTypeRouter as part of Spring Integration DSL as follows:

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();

After I send xml message into queue, SI complains with

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]

Any idea what workaround to apply?

Upvotes: 2

Views: 960

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121442

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

or use Spring Integration Java DSL 1.2 already with Spring Integration 4.3.1. The Class<?> as a routing key has been fixed in the https://jira.spring.io/browse/INT-4057.

With that you don't need to use .toString() for classes. The sample from project tests:

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

Upvotes: 3

Related Questions