You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by xgeoff <gp...@yahoo.com> on 2009/06/22 19:17:30 UTC

Issues with Quickstart docs and examples

I don't know if anyone else had these problems with the quickstart example in
the Camel docs, but it took me a while to figure out how to get it to work. 
Here is my final test class (working) with some commentary about what is in
the docs, and why they didn't work for me, and why I can't understand how
they could ever work without the changes I made.

In addition, there are a bunch of jar files you need to have added as
references, including some that are in the "optional" folder, such as
activemq-pool.x.x.x.jar.  My friends, they are not optional ;)


// you'll need all these imports
import org.apache.camel.*;
import org.apache.camel.builder.*;
import org.apache.camel.impl.*;
import org.apache.activemq.camel.component.*;

/**
 *
 * @author 
 */
public class Tests {

    public static void main(String[] args) {

        try {
            CamelContext context = new DefaultCamelContext();

            /* you have to add this component with the name "test-jms", not
"activemq" like
                it is in the docs. I can't understand how it would ever work
by naming your component
                "activemq" when nothing in the example looks for a component
by that name?

                Also, you'll notice that the call to the activeMQComponent()
method actually specifies
                the class that you are calling the the method on
(ActiveMQComponent).  Again, I don't
                know how you could call a method without stating the class
or object, unless you were
                within an object that contained that method.  In any case,
being explicit never hurts,
                and this illustrates where you're getting that method from.

                Everything else works pretty much according to the docs, but
there was another discrepency
                I saw with regards to the following line:

                              ConnectionFactory connectionFactory = new
                                          
ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");

               The ActiveMQConnectionFactory Class that I have in this
namespace:

                              org.apache.activemq.spring

               only supports an empty constructor.  What version are you
using that you can supply a String
               to the constructor?

            */
            context.addComponent("test-jms",
                   
ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"));
            
            context.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("test-jms:queue:test.queue").to("file://test");
                    // set up a listener on the file component
                    from("file://test").process(new Processor() {

                        public void process(Exchange e) {
                            System.out.println("Received exchange: " +
e.getIn());
                        }
                    });
                }
            });


            ProducerTemplate template = context.createProducerTemplate();

            context.start();

            for (int i = 0; i < 10; i++) {
                template.sendBody("test-jms:queue:test.queue", "Test
Message: " + i);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


-- 
View this message in context: http://www.nabble.com/Issues-with-Quickstart-docs-and-examples-tp24151688p24151688.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issues with Quickstart docs and examples

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Thanks a lot for sharing this.

Yeah with Java you always need a ton of .jars in the classpath :)

Usually it helps with maven or ivy as they can help find the jars for you.


On Mon, Jun 22, 2009 at 7:17 PM, xgeoff<gp...@yahoo.com> wrote:
>
> I don't know if anyone else had these problems with the quickstart example in
> the Camel docs, but it took me a while to figure out how to get it to work.
> Here is my final test class (working) with some commentary about what is in
> the docs, and why they didn't work for me, and why I can't understand how
> they could ever work without the changes I made.
>
> In addition, there are a bunch of jar files you need to have added as
> references, including some that are in the "optional" folder, such as
> activemq-pool.x.x.x.jar.  My friends, they are not optional ;)
>
>
> // you'll need all these imports
> import org.apache.camel.*;
> import org.apache.camel.builder.*;
> import org.apache.camel.impl.*;
> import org.apache.activemq.camel.component.*;
>
> /**
>  *
>  * @author
>  */
> public class Tests {
>
>    public static void main(String[] args) {
>
>        try {
>            CamelContext context = new DefaultCamelContext();
>
>            /* you have to add this component with the name "test-jms", not
> "activemq" like
>                it is in the docs. I can't understand how it would ever work
> by naming your component
>                "activemq" when nothing in the example looks for a component
> by that name?
>
>                Also, you'll notice that the call to the activeMQComponent()
> method actually specifies
>                the class that you are calling the the method on
> (ActiveMQComponent).  Again, I don't
>                know how you could call a method without stating the class
> or object, unless you were
>                within an object that contained that method.  In any case,
> being explicit never hurts,
>                and this illustrates where you're getting that method from.
>
>                Everything else works pretty much according to the docs, but
> there was another discrepency
>                I saw with regards to the following line:
>
>                              ConnectionFactory connectionFactory = new
>
> ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
>
>               The ActiveMQConnectionFactory Class that I have in this
> namespace:
>
>                              org.apache.activemq.spring
>
>               only supports an empty constructor.  What version are you
> using that you can supply a String
>               to the constructor?
>
>            */
>            context.addComponent("test-jms",
>
> ActiveMQComponent.activeMQComponent("vm://localhost?broker.persistent=false"));
>
>            context.addRoutes(new RouteBuilder() {
>
>                public void configure() {
>                    from("test-jms:queue:test.queue").to("file://test");
>                    // set up a listener on the file component
>                    from("file://test").process(new Processor() {
>
>                        public void process(Exchange e) {
>                            System.out.println("Received exchange: " +
> e.getIn());
>                        }
>                    });
>                }
>            });
>
>
>            ProducerTemplate template = context.createProducerTemplate();
>
>            context.start();
>
>            for (int i = 0; i < 10; i++) {
>                template.sendBody("test-jms:queue:test.queue", "Test
> Message: " + i);
>            }
>
>        } catch (Exception e) {
>            e.printStackTrace();
>        }
>    }
> }
>
>
> --
> View this message in context: http://www.nabble.com/Issues-with-Quickstart-docs-and-examples-tp24151688p24151688.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus