3

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

Mike
  • 541
  • 1
  • 4
  • 18

1 Answers1

5

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Edited the question. There was the route before the `channelMapping`, so I think I need the `channelMapping`. So how to route with the channelMapping method to the channel which name is in the headers? – Mike Nov 13 '18 at 10:46
  • Ok. You can include that into the routing function as well. I mean you do ternary operator and return the channel you need. The mapping is only for static channels – Artem Bilan Nov 13 '18 at 12:29
  • Thanks for the answer – Mike Nov 19 '18 at 11:54