Coverage Report - org.apache.camel.example.jmstofile.CamelJmsToFileExample
 
Classes in this File Line Coverage Branch Coverage Complexity
CamelJmsToFileExample
0% 
0% 
1.25
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.example.jmstofile;
 18  
 
 19  
 import javax.jms.ConnectionFactory;
 20  
 
 21  
 import org.apache.activemq.ActiveMQConnectionFactory;
 22  
 import org.apache.camel.CamelContext;
 23  
 import org.apache.camel.CamelTemplate;
 24  
 import org.apache.camel.Exchange;
 25  
 import org.apache.camel.Processor;
 26  
 import org.apache.camel.builder.RouteBuilder;
 27  
 import org.apache.camel.component.jms.JmsComponent;
 28  
 import org.apache.camel.impl.DefaultCamelContext;
 29  
 
 30  
 /**
 31  
  * An example class for demonstrating some of the basics behind camel This
 32  
  * example will send some text messages on to a JMS Queue, consume them and
 33  
  * persist them to disk
 34  
  * 
 35  
  * @version $Revision: 529902 $
 36  
  */
 37  
 public final class CamelJmsToFileExample {
 38  
 
 39  0
     private CamelJmsToFileExample() {        
 40  0
     }
 41  
     
 42  
     public static void main(String args[]) throws Exception {
 43  
         // START SNIPPET: e1
 44  0
         CamelContext context = new DefaultCamelContext();
 45  
         // END SNIPPET: e1
 46  
         // Set up the ActiveMQ JMS Components
 47  
         // START SNIPPET: e2
 48  0
         ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
 49  
         // note we can explicity name the component
 50  0
         context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
 51  
         // END SNIPPET: e2
 52  
         // Add some configuration by hand ...
 53  
         // START SNIPPET: e3
 54  0
         context.addRoutes(new RouteBuilder() {
 55  
 
 56  0
             public void configure() {
 57  0
                 from("test-jms:queue:test.queue").to("file://test");
 58  
                 // set up a listener on the file component
 59  0
                 from("file://test").process(new Processor() {
 60  
 
 61  0
                     public void process(Exchange e) {
 62  0
                         System.out.println("Received exchange: " + e.getIn());
 63  0
                     }
 64  
                 });
 65  0
             }
 66  
         });
 67  
         // END SNIPPET: e3
 68  
         // Camel template - a handy class for kicking off exchanges
 69  
         // START SNIPPET: e4
 70  0
         CamelTemplate template = new CamelTemplate(context);
 71  
         // END SNIPPET: e4
 72  
         // Now everything is set up - lets start the context
 73  0
         context.start();
 74  
         // now send some test text to a component - for this case a JMS Queue
 75  
         // The text get converted to JMS messages - and sent to the Queue
 76  
         // test.queue
 77  
         // The file component is listening for messages from the Queue
 78  
         // test.queue, consumes
 79  
         // them and stores them to disk. The content of each file will be the
 80  
         // test test we sent here.
 81  
         // The listener on the file component gets notfied when new files are
 82  
         // found ...
 83  
         // that's it!
 84  
         // START SNIPPET: e5
 85  0
         for (int i = 0; i < 10; i++) {
 86  0
             template.sendBody("test-jms:queue:test.queue", "Test Message: " + i);
 87  
         }
 88  
         // END SNIPPET: e5
 89  0
         Thread.sleep(1000);
 90  0
         context.stop();
 91  0
     }
 92  
 }