I want to set some common header/properties in the message produced via camel ProducerTemplate. This is useful when we want to attach some common properties to all outgoing messages.
For example, to send a message with a header we can write the following
template.sendBodyAndHeader("direct:route", "Hello World", "X-Common-Header", "demo-value");
But, it would be great if we can do something like
// This line of code would be present wherever the producer template bean is being created/initialized
template.attachInterceptor((exchange) -> exchange.getIn().setHeader("X-Common-Header", "demo-value"));
// This line of code could be anywhere wherever we are producing messages
template.sendBody("direct:route", "Hello World");
For incoming messages, there is already RouteConfiguration which does this job well.