Re: How to keep route running on camel with JavaDSL?
Hey guys, I want to thank for all the help and suggestions. However I got an answer from someone else at stackoverflow that suggested I should use this: http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html After that I decided to check the Camel in Action book and I just finished reading chapter 13.4.1 where they also talk about using this Java class. I am a little confused with the differences between the start() and run() methods, so I checked documentation here: http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/main/Main.html But I could not find anything that would explain it to me. Anyway, I am now using it and I must say it sure is a lot easier than I expected ! -- View this message in context: http://camel.465427.n5.nabble.com/How-to-keep-route-running-on-camel-with-JavaDSL-tp5742677p5742727.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: How to keep route running on camel with JavaDSL?
start() is the method from Camel Service interface, so you can think it just start the services of camel. But run() need to do some addition work after calling the start() method, such as block the main thread to avoid exiting the process and do some clean up work after camel is shutdown. -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Wednesday, November 6, 2013 at 11:50 PM, pmp.martins wrote: Hey guys, I want to thank for all the help and suggestions. However I got an answer from someone else at stackoverflow that suggested I should use this: http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html After that I decided to check the Camel in Action book and I just finished reading chapter 13.4.1 where they also talk about using this Java class. I am a little confused with the differences between the start() and run() methods, so I checked documentation here: http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/main/Main.html But I could not find anything that would explain it to me. Anyway, I am now using it and I must say it sure is a lot easier than I expected ! -- View this message in context: http://camel.465427.n5.nabble.com/How-to-keep-route-running-on-camel-with-JavaDSL-tp5742677p5742727.html Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).
Re: How to keep route running on camel with JavaDSL?
Hi Yeah check this page http://camel.apache.org/running-camel-standalone.html And the cookbook example it refers to. On Tue, Nov 5, 2013 at 11:19 PM, pmp.martins pmp.mart...@campus.fct.unl.pt wrote: I have code a loadbalancer that generates a report every 10 seconds and sends it to a MINA server on localhost:9991 or to a MINA server on localhost:9992 should the first one fail. Once the MINA servers receive the report, they change it and send it back to the loadbalancer, which then print the body of the report. public class MyApp_A { public static void main(String... args) throws Exception { // create CamelContext CamelContext context = new DefaultCamelContext(); context.addRoutes( new RouteBuilder(){ @Override public void configure() throws Exception { from(timer://org.apache.camel.example.loadbalancer?period=10s) .beanRef(service.Generator, createReport) .to(direct:loadbalance); from(direct:loadbalance) .loadBalance().failover() // will send to A first, and if fails then send to B afterwards .to(mina:tcp://localhost:9991?sync=true) .to(mina:tcp://localhost:9992?sync=true) .log(${body}) .end(); } } ); context.start(); } } However, once I execute the loadbalancer it finishes immediately. I tried fixing this problem by adding an infinite loop after the context.start() call, however this is a terrible solution because the program will simply get stuck on the loop and will stop generating reports and sending them. How do I fix this? How do I keep my loadbalancer running while being able to generate requests and print the reports that it receives? -- View this message in context: http://camel.465427.n5.nabble.com/How-to-keep-route-running-on-camel-with-JavaDSL-tp5742677.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen
Re: How to keep route running on camel with JavaDSL?
When you start the camel route in the main, you need to add a sleep to block the main thread from exit. BTW, you can use other tools that camel provides to running the camel route as Claus just showed you. -- Willem Jiang Red Hat, Inc. Web: http://www.redhat.com Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English) http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese) Twitter: willemjiang Weibo: 姜宁willem On Wednesday, November 6, 2013 at 6:19 AM, pmp.martins wrote: I have code a loadbalancer that generates a report every 10 seconds and sends it to a MINA server on localhost:9991 or to a MINA server on localhost:9992 should the first one fail. Once the MINA servers receive the report, they change it and send it back to the loadbalancer, which then print the body of the report. public class MyApp_A { public static void main(String... args) throws Exception { // create CamelContext CamelContext context = new DefaultCamelContext(); context.addRoutes( new RouteBuilder(){ @Override public void configure() throws Exception { from(timer://org.apache.camel.example.loadbalancer?period=10s) .beanRef(service.Generator, createReport) .to(direct:loadbalance); from(direct:loadbalance) .loadBalance().failover() // will send to A first, and if fails then send to B afterwards .to(mina:tcp://localhost:9991?sync=true) .to(mina:tcp://localhost:9992?sync=true) .log(${body}) .end(); } } ); context.start(); } } However, once I execute the loadbalancer it finishes immediately. I tried fixing this problem by adding an infinite loop after the context.start() call, however this is a terrible solution because the program will simply get stuck on the loop and will stop generating reports and sending them. How do I fix this? How do I keep my loadbalancer running while being able to generate requests and print the reports that it receives? -- View this message in context: http://camel.465427.n5.nabble.com/How-to-keep-route-running-on-camel-with-JavaDSL-tp5742677.html Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).