package com.boundary.sdk;

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 static final String DEFAULT_QUEUE_NAME="direct:queue";

	public QueueRouteBuilder() {
		queueName = DEFAULT_QUEUE_NAME;
	}
	
	/**
	 * Sets the name of JMS queue
	 * 
	 * @param queueName
	 */
	public void setQueueName(String queueName) {
		this.queueName = queueName;
	}
	
	/**
	 * Gets the name of the JMS queue
	 * 
	 * @return
	 */
	public String getQueueName() {
		return this.queueName;
	}
	

    @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));

        // load file orders from src/data into the JMS queue
        from(fromUri)
        .routeId(routeId)
        .to("jms:pending_events?asyncConsumer=true")
        .to("log:com.boundary.sdk.QueueRouterBuilder?level=INFO&groupInterval=10000&groupDelay=60000&groupActiveOnly=false")
        .to(toUri);

//        // content-based router
//        from("jms:incomingOrders")
//        .choice()
//            .when(header("CamelFileName").endsWith(".xml"))
//                .to("jms:topic:xmlOrders")  
//            .when(header("CamelFileName").endsWith(".csv"))
//                .to("jms:topic:csvOrders");
//
//        from("jms:topic:xmlOrders").to("jms:accounting");  
//        from("jms:topic:xmlOrders").to("jms:production");  
//        
//        // test that our route is working
//        from("jms:accounting").process(new Processor() {
//            public void process(Exchange exchange) throws Exception {
//                System.out.println("Accounting received order: "
//                        + exchange.getIn().getHeader("CamelFileName"));  
//            }
//        });
//        from("jms:production").process(new Processor() {
//            public void process(Exchange exchange) throws Exception {
//                System.out.println("Production received order: "
//                        + exchange.getIn().getHeader("CamelFileName"));  
//            }
//        });
    }    
}

@@ -1049,24 +1049,16 @@
 );%0A    %09
-        
 // conne
@@ -1092,16 +1092,16 @@
  broker%0A
+
         
@@ -1310,59 +1310,79 @@
    /
-/ load file orders from src/data into the JMS queue
+**%0A         * Receives serialized @%7Blink RawEvent%7D messages%0A         */
 %0A   
@@ -1475,32 +1475,26 @@
 umer=true%22)%0A
-        
+%09%09
 .to(%22log:com
@@ -1517,17 +1517,16 @@
 eueRoute
-r
 Builder?
@@ -1535,1191 +1535,75 @@
 vel=
-INFO&groupInterval=10000&groupDelay=60000&groupActiveOnly=false%22)%0A        .to(toUri);%0A%0A//        // content-based router%0A//        from(%22jms:incomingOrders%22)%0A//        .choice()%0A//            .when(header(%22CamelFileName%22).endsWith(%22.xml%22))%0A//                .to(%22jms:topic:xmlOrders%22)  %0A//            .when(header(%22CamelFileName%22).endsWith(%22.csv%22))%0A//                .to(%22jms:topic:csvOrders%22);%0A//%0A//        from(%22jms:topic:xmlOrders%22).to(%22jms:accounting%22);  %0A//        from(%22jms:topic:xmlOrders%22).to(%22jms:production%22);  %0A//        %0A//        // test that our route is working%0A//        from(%22jms:accounting%22).process(new Processor() %7B%0A//            public void process(Exchange exchange) throws Exception %7B%0A//                System.out.println(%22Accounting received order: %22%0A//                        + exchange.getIn().getHeader(%22CamelFileName%22));  %0A//            %7D%0A//        %7D);%0A//        from(%22jms:production%22).process(new Processor() %7B%0A//            public void process(Exchange exchange) throws Exception %7B%0A//                System.out.println(%22Production received order: %22%0A//                        + exchange.getIn().getHeader(%22CamelFileName%22));  %0A//            %7D%0A//        %7D)
+DEBUG&showHeaders=true&multiline=true%22)%0A        .to(toUri)%0A        
 ;%0A  

Clean up commented out code from example