2

I have it like this currently:

.route("headers.STATE", new Consumer<RouterSpec<ExpressionEvaluatingRouter>>() {
        @Override
        public void accept(RouterSpec<ExpressionEvaluatingRouter> spec) {
            spec
                .channelMapping(ProcStatus.NORMAL_OPERATION.toString(), "primaryChannel")
                .channelMapping(ProcStatus.FAILED_OVER.toString(), "secondaryChannel")
                .channelMapping(ProcStatus.UNKNOWN.toString(), "stateRetrievalChannel");
                }
            })

But it's not really a header value router per se right? I can't seem to set HeaderValueRouter as the routing spec and just give the name of the header on the first param.

Plus i couldn't find a default channel mapping on the spec. Thanks for the help!

alokraop
  • 853
  • 1
  • 11
  • 29

1 Answers1

3

To be honest the <header-value-router> does not make sense since introduction of SpEL router, where you can simply configure it like expression="headers.STATE", like in your config for Java DSL.

Everything else is the same for any kind of Router implementation. See more in the reference manual.

And, yes, you can use HeaderValueRouter directly as well:

.route(new HeaderValueRouter("STATE"), new Consumer<RouterSpec<ExpressionEvaluatingRouter>>() {
    @Override
    public void accept(RouterSpec<ExpressionEvaluatingRouter> spec) {
        spec
            .channelMapping(ProcStatus.NORMAL_OPERATION.toString(), "primaryChannel")
            .channelMapping(ProcStatus.FAILED_OVER.toString(), "secondaryChannel")
            .channelMapping(ProcStatus.UNKNOWN.toString(), "stateRetrievalChannel");
            }
        })

But as you see the .channelMapping() remains the same.

As for "default channel mapping". I think you just mean default-output-channel, which we have in the XML configuration.

If you noticed no one component in the SI Java DSL has an output-channel option (the default-output-channel plays the same role). We just propagate the next .channel() definition in the IntegrationFlow to the current outputChannel-aware component. So, to map the default-output-channel for the .route() you should just go ahead in the method-chain with the IntegrationFlow definition. Like this:

.route()
.handle()

So, if routing condition doesn't meet any .channelMapping() and resolutionRequired == false, the message will be send to the next .handle() through the implicit DirectChannel between them.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Oh cool. I did try adding to the chain but i didn't know about the bool, thanks. The reference mentioned there's native support for header value router which kinda got me confused since the one in the dsl is a content based one. But i guess it was talking about spring integration rather than dsl specifically. Thanks for clarifying :) – alokraop Nov 12 '15 at 12:30