package com.boundary.sdk.event;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;

import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;


/**
 * Builds are route that is Queue using ActiveMQ
 * 
 * @author davidg
 *
 */
public class QueueRouteBuilder extends BoundaryRouteBuilder {
	
	private String queueName;

	private int concurrentConsumers;

	private boolean asyncConsumer;
	
	private static final String DEFAULT_QUEUE_NAME="pending_events";
	private static final int DEFAULT_CONCURRENT_CONSUMERS=1;

	public QueueRouteBuilder() {
		queueName = DEFAULT_QUEUE_NAME;
		concurrentConsumers = DEFAULT_CONCURRENT_CONSUMERS;
		asyncConsumer = true;
	}
	
	/**
	 * Sets the name of JMS queue
	 * 
	 * @param queueName
	 */
	public void setQueueName(String queueName) {
		this.queueName = queueName;
	}
	
	/**
	 * Gets the name of the JMS queue
	 * 
	 * @return Name of the JMS queue
	 */
	public String getQueueName() {
		return this.queueName;
	}
	
	/**
	 * Sets the number of concurrent consumers use by ActiveMQ
	 */
	public void setConcurrentConsumers(int consumers) {
		this.concurrentConsumers = consumers;
	}

	/**
	 * Sets the queue consumers to be asynchronous
	 * @param async
	 */
	public void setAsyncConsumer(boolean async) {
			this.asyncConsumer = async;
	}

    @Override
    public void configure() {
    	
    	CamelContext  context = getContext();
    	// connect to embedded ActiveMQ JMS broker
        ConnectionFactory connectionFactory =
            new ActiveMQConnectionFactory("vm://localhost");
        context.addComponent("jms",JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        String jmsUri = String.format("jms:%s?asyncConsumer=%s",queueName,asyncConsumer);

        /**
         * Receives serialized @{link RawEvent} messages
         */
        from(fromUri)
        .startupOrder(startUpOrder)
        .routeId(routeId)
        .to(jmsUri)
		.to("log:com.boundary.sdk.QueueRouteBuilder?level=DEBUG&showHeaders=true&multiline=true")
        .to(toUri)
        ;
    }    
}

@@ -615,16 +615,41 @@
 onsumer;
+%0A%0A%09private String jmsUri;
 %0A%09%0A%09priv
@@ -910,16 +910,45 @@
 = true;%0A
+%09%09jmsUri = %22vm://localhost%22;%0A
 %09%7D%0A%09%0A%09/*
@@ -1560,16 +1560,79 @@
 sync;%0A%09%7D
+%0A%09%0A%09public void setJmsUri(String uri) %7B%0A%09%09this.jmsUri = uri;%0A%09%7D
 %0A%0A    @O
@@ -1854,32 +1854,27 @@
 Factory(
-%22vm://localhost%22
+this.jmsUri
 );%0A     

Add proprety JmsUri so as not to hardwire the configuration in the code. A suitable default is provided if no value is provided for this property