Hi

That is because the ctr is creating a local instance, eg

 CamelContext camelContext = new DefaultCamelContext();

should be

 camelContext = new DefaultCamelContext();

On Wed, Apr 26, 2017 at 11:59 AM, gelawlor <[email protected]> wrote:
> Hi,
>
> I am implementing a Camel based connector service to ActiveMQ and the class
> outline looks as follows:
>
> public class ActiveMQCamelRouterService {
>
>         private CamelContext camelContext;
>     private ProducerTemplate camelTemplate;
>
>
>         public ActiveMQCamelRouterService()
>         {
>                 try
>                 {
>                         CamelContext camelContext = new DefaultCamelContext();
>                         ActiveMQComponent queue =
> ActiveMQComponent.activeMQComponent("tcp://localhost:61616?broker.persistent=false");
>                 queue.setBrokerURL("tcp://localhost:61616");
>                 camelContext.addComponent("activemq", queue);
>                 camelTemplate = camelContext.createProducerTemplate();
>          }
>                 catch(...)
>                 {
>                 }
>         }
>
>     public void process(SOAPEnvelope req, SOAPEnvelope resp) throws
> Exception {
>                 try
>                 {
>                         Node requestNode = getMessageNode(req);
>                         if(requestNode!=null)
>                         {
>                                 final String routeSource = "direct:activemq";
>                                 final String routeDestination = 
> "activemq:queue:testqueue";
>
>                                 if( camelContext != null )
>                                 {
>                                         camelContext.addRoutes(new 
> RouteBuilder() {
>                                     public void configure() throws Exception {
>                                         
> from(routeSource).to(routeDestination);
>                                     }
>                                 });
>
>                         camelContext.start();
>
>                         //need to understand how to shape message with 
> headers to
> activemq through camel
>                         camelTemplate.sendBody(routeSource, "This is a test 
> message
> from Camel");
>                 }
>
>                 }
>                 }
>                 catch(...)
> }
>
> What I have noticed is that the Camel context is initialized in the
> constructor but is NULL when the process method is called. I have tested
> this code instantiating other objects in the constructor and can see they
> are valid in the process method. Do you know if this is a known issue or
> design feature of Camel ? Would this happen if somehow I got the mix of jars
> (Camel, Camel-ActiveMQ and Spring) matched up incorrectly?
>
> Thanks,
> Ger.
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Camel-context-NULL-in-derived-class-tp5798307.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to