Spring Integration Java DSL: How to route with the channelMapping method to the channel which name is in the headers?

Viewed 779

How to route with the channelMapping method to the channel which name is in the headers? So if I try this

    @Bean
    private IntegrationFlow postDataToChannelX() {
            return f -> f
            ...
               .<String, Boolean> route(s -> s.equals("[]"), m -> m
                    .channelMapping(false, "headers['channelName']")
                    .channleMapping(true, ...);
    }

there comes

Caused by: org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'headers['channelName']' in the BeanFactory.; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'headers['channelName']' available

1 Answers

You can just do like this:

.route(Message.class, (m) -> m.getHeaders().get("channelName"))

So, you don't need any mapping at all since you resolve to the target channel directly in the routing function.

Related