The RabbitMqProducer and RabbitMqPublisher do not honor the EXCHANGE_OVERRIDE_NAME header when used for a routing Key not starting with
For example :
from("stream:in?promptMessage=Enter message payload: ").setHeader(RabbitMQConstants.EXCHANGE_OVERRIDE_NAME,constant("")).setHeader(RabbitMQConstants.ROUTING_KEY,constant("test"))
will publish the message with the routing key "test" on the "uselessExchange" exchange instead of the expected "" (default exchange).
This seems to come from a conflict between :
- org.apache.camel.component.rabbitmq.RabbitMQProducer#processInOnly which extract and remove the exchange override name, then pass it to org.apache.camel.component.rabbitmq.RabbitMQProducer#basicPublish where it is not used.
- _org.apache.camel.component.rabbitmq.RabbitMQMessagePublisher#publishToRabbit_MQ (that is called by the previous function through the ChannelCallback) where the Exchange override name is once again removed (though it is null now, since it has been removed previously)
Note that when the routing key starts with RABBITMQ_DIRECT_REPLY_ROUTING_KEY the behavior is almost correct thanks to org.apache.camel.component.rabbitmq.RabbitMQMessagePublisher#resolveMessageFrom
which overrides the exchange_override_name with the default exchange.
I would gladly create a PR or a patch with a correction, but I'm not sure of the intended behavior ?
- do not extract the EXCHANGE_OVERRIDE_NAME in the org.apache.camel.component.rabbitmq.RabbitMQProducer#processInOnly
- Extract it but make sure it goes all the way down to the org.apache.camel.component.rabbitmq.RabbitMQMessagePublisher#RabbitMQMessagePublisher constructor where it could be saved and reused later by the org.apache.camel.component.rabbitmq.RabbitMQMessagePublisher#publishToRabbitMQ
In my Opinion the best solution would be to remove the extraction of the header in
org.apache.camel.component.rabbitmq.RabbitMQProducer#processInOnly (and org.apache.camel.component.rabbitmq.RabbitMQProducer#processInOut)