Darshana
Darshana

Reputation: 2548

How to trigger a route from a timer

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

Answers (1)

whaley
whaley

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

Related Questions