Reputation: 1277
I have a main route builder:
public class MainRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("activemq:a.out").to("activemq:b.in");
from("activemq:b.in").bean(MainMessageConsumer.class);
}
}
I have a second "intercept" route builder:
public class InterceptRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("activemq:a.out").to("activemq:c.in").skipSendToOriginalEndpoint();
from("activemq:c.in").bean(InterceptMessageConsumer.class);
}
}
Both of which are registered to the CamelContext (MainRouteBuilder is registered first, and InterceptRouteBuilder second). However, when I send a message to "activemq:a.out" via:
public class App {
@Produce(uri="activemq:a.out")
private Producer producer;
public void run() {
producer.request("hello");
}
}
The message still arrives on MainMessageConsumer instead of being intercepted. What am I doing wrong?
Upvotes: 2
Views: 3143
Reputation: 1277
Seems to be that if you create your producer using the @Produce annotation, then it won't be intercepted. Whereas if I put:
@Bean
public ProducerTemplate producerTemplate() {
return camelContext().createProducerTemplate();
}
In my application config, and use that instead then it does get intercepted. Not sure if this is the expected behaviour?
Upvotes: 0
Reputation: 55545
The interceptor only applies for all routes in the same route builder class. If you want it to work on both, then create a base class, and put the interceptor there, and let the other routes extend your base class, and call its super in the configure method (eg OO inheritance)
Upvotes: 5