RnD-John commented on issue #1079: Example Request: CamelJmsToFileExample.java
URL: https://github.com/apache/camel-k/issues/1079#issuecomment-565456102
 
 
   per @lburgazzoli 
   > I think your issue is that the connection factory is instantiated at class 
constructions, you should move it to the `configure` method as the injection 
happens after the class has been constructed, before that the url is null
   
   **This fixes the issue**. Thank you for the assistance. For those 
interested, the new code is as follows:
   
   > import org.apache.camel.builder.RouteBuilder;
   > import org.apache.camel.CamelContext;
   > import org.apache.camel.component.jms.JmsComponent;
   > import org.apache.camel.ProducerTemplate;
   > import org.apache.camel.PropertyInject;
   > 
   > import javax.jms.ConnectionFactory;
   > 
   > import org.apache.activemq.ActiveMQConnectionFactory;
   > 
   > public class BasicAMQ extends RouteBuilder
   > {
   >     //standard java, need to inject properties to use them//
   >     @PropertyInject("my.uri")
   >     private String uri;
   >     @PropertyInject("my.component")
   >     private String component;
   > 
   >     @Override
   >     public void configure() throws Exception
   >     {
   >         ConnectionFactory connectionFactory = new 
ActiveMQConnectionFactory(uri);
   > 
   >         CamelContext context = getContext();
   >         context.addComponent(component, 
JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
   > 
   >         //DSL starts here, can directly use {{}} syntax for properties//
   >         from("{{my.component}}:queue:{{my.queue}}.queue")
   >         .log("{{my.prefix}} ${body} ");
   >     }
   > }
   
   Run via:
   
   > kamel run -d mvn:org.apache.activemq:activemq-all:5.5.1 -d 
mvn:org.apache.activemq:activemq-camel:5.5.1 -p my.uri="<MY_URI>" -p 
my.component="test-jms" -p my.queue="camelktestParametric" -p my.prefix="Got a 
message: " --name "ParameterizedBAMQ" BasicAMQ.java 
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to