Reputation: 2548
I want to trigger a route form a timer task. When the run method calls. I have use ProducerTemplate
with the annotation @Produce
. But it throws null point exception because of producerTemplate
is null.
public class ReminderTask extends TimerTask {
@Produce
private ProducerTemplate producerTemplate;
@Override
public void run() {
final Exchange defaultExchange = new DefaultExchange(new DefaultCamelContext());
producerTemplate.send("direct:simpleRoute", defaultExchange);
}
}
Upvotes: 1
Views: 101
Reputation: 16265
In order for the @Produce annotation to work your ReminderTask instance needs to be container managed (e.g. camel-spring, blueprint).
Otherwise, you must explicitly initialize your ProducerTemplate field from the CamelContext instance that defines your "direct:simpleRoute" endpoint.
It's difficult to further answer this question without knowing more about how your CamelContext is created (and managed).
Upvotes: 1