Invoke a Route on bundle StartUp
niteshjain132 Feb 10, 2015 6:07 AMServer - Jboss Fuse 6.0
Trying to invoke a route when the ApplicationContext is loaded successfully using ApplicationContextAware Interface.
package com.test;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.DefaultExchange;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class ContextAware implements ApplicationContextAware {
public static CamelContext context;
public static CamelContext getContext() {
return context;
}
public static void setContext(CamelContext context) throws Exception {
ContextAware.context = context;
}
public void setApplicationContext(ApplicationContext ac) throws BeansException {
try {
ContextAware.setContext((CamelContext) ac.getBean("hazel_camel"));
System.out.println("-----------Invoking route----------------");
ProducerTemplate template = ContextAware.context.createProducerTemplate();
Exchange exchange=new DefaultExchange(ContextAware.context);
template.send("direct:getMessageProcessor",exchange);
System.out.println("-----------END----------------");
} catch (Exception e) {
e.printStackTrace();
}
}
}
the "direct:getMessageProcessor" is not invoking the processor associated with it in camel_context.xml :
<camelContext trace="false" id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="getMessageProcessor">
<from uri="direct:getMessageProcessor" />
<process ref="getMessage" />
</route>
</camelContext>
<bean id="getMessage" class="com.test.GetMessageProcessor" />
i get this in log -
org.apache.camel.camel-core - 2.12.0.redhat-610379 | Route: getMessageProcessor started and consuming from: Endpoint[direct://getMessageProcessor]
but GetMessageProcessor.java is not invoked,
Thanks,
Nitesh