You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by abhimukh <wr...@live.com> on 2013/08/22 15:26:33 UTC
How to called the processor
Hi, am novice to Apache camel, I want to write the Standalone Camel class,
just to called the processor for this i had written the following class and
expect it should print the message on the console but its not working.
can somebody help in this, how can i achieve it, and what am missing, the
class written is as follow
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class CamelGroovyIntegrationTest {
public static void main (String args[])throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("control in processor");
}
});
}
});
context.start();
Thread.sleep(10000);
context.stop();
}
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-called-the-processor-tp5737769.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to called the processor
Posted by jhonny <wr...@live.com>.
thanks for the help..
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-called-the-processor-tp5737769p5738324.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: AW: How to called the processor
Posted by pradeep <pr...@gmail.com>.
The below mentioned code snippet works as you expected.
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder()
{
@Override
public void configure() throws Exception
{
from("direct:start").process(new Processor()
{
@Override
public void process(Exchange exchange) throws Exception
{
System.out.println("control in
processor!!!!!!!!!!!!!!!");
}
});
}
});
context.start();
Thread.sleep(1000);
ProducerTemplate template = context.createProducerTemplate();
template.sendBody("direct:start", "Test Message");
context.stop();
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-called-the-processor-tp5737769p5737941.html
Sent from the Camel - Users mailing list archive at Nabble.com.
AW: How to called the processor
Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
>
> *can i able to do as below, if not then how can i acheive it ?*
>
> from("direct:start").process(new Processor() {
>
> @Override
> public void process(Exchange
exchange)
> throws Exception {
> System.out.println("control in
> processor");
>
> }
> });
Sure, you could.
In your first example you create a route, wait 10s for incoming messages and
then exit.
And if a message would come, you could see your console output.
But you havent send a message to your "direct:start" endpoint.
So your little Camel application had not trigger to react on.
That's why your blog uses "timer://timer1?period=1000", which means "every
1s".
Another way would sending a message using a ProducerTemplate (see
http://camel.apache.org/walk-through-an-example.html).
ProducerTemplate template = context.createProducerTemplate();
template.sendBody("direct:start", "Test Message");
Jan
Re: How to called the processor
Posted by abhimukh <wr...@live.com>.
on the blog "http://saltnlight5.blogspot.se" there is an example where route
is created as follow
from("timer://timer1?period=1000")
.process(new Processor() {
public void process(Exchange msg) {
LOG.info("Processing {}", msg);
}
});
*can i able to do as below, if not then how can i acheive it ?*
from("direct:start").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("control in processor");
}
});
--
View this message in context: http://camel.465427.n5.nabble.com/How-to-called-the-processor-tp5737769p5737774.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to called the processor
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Try for example the console example
http://camel.apache.org/console-example.html
And in your example you can use a timer or something to schedule the
route to start
http://camel.apache.org/timer
And see for example this blog about using Camel with Java
http://saltnlight5.blogspot.se/2013/08/getting-started-with-apache-camel-using.html
You can find many articles / blogs about introducing Camel from this page
http://camel.apache.org/articles
On Thu, Aug 22, 2013 at 3:26 PM, abhimukh <wr...@live.com> wrote:
> Hi, am novice to Apache camel, I want to write the Standalone Camel class,
> just to called the processor for this i had written the following class and
> expect it should print the message on the console but its not working.
>
> can somebody help in this, how can i achieve it, and what am missing, the
> class written is as follow
>
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.impl.DefaultCamelContext;
>
> public class CamelGroovyIntegrationTest {
>
> public static void main (String args[])throws Exception {
> CamelContext context = new DefaultCamelContext();
>
> context.addRoutes(new RouteBuilder() {
>
> @Override
> public void configure() throws Exception {
>
>
> from("direct:start").process(new Processor() {
>
> @Override
> public void process(Exchange exchange) throws Exception {
> System.out.println("control in processor");
>
> }
> });
>
> }
> });
>
> context.start();
> Thread.sleep(10000);
> context.stop();
> }
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-called-the-processor-tp5737769.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen