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!

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.