Camel route with .method() - Unit Testing
Hello, I am currently trying to write a unit test for a camel route which contains a .method(beanId,methodName) component: from(this.incomingSource) .split().method(splitterBean, splitMessages) .choice() .when(isValid) .marshal(jaxb).to(this.outgoingDestination) .otherwise() .processRef(errorReportingProcessor).to(this.invalidDestination) .end(); In the Test class I have the following lines for the @Before method : @Before public void beforeTest() throws Exception { this.context = new DefaultCamelContext(); this.route = new SplittingMainRoute(); this.route.setIncomingSource(mokc:in); this.route.setOutgoingDestination(mock:out); this.route.setInvalidDestination(mock:isValid); this.context.addRoutes(this.route); this.context.start(); this.producer = this.context.createProducerTemplate(); } I'm actually running Camel on Fuse-Servicemix and the splitterBean bean is defined in the bundle-context.xml as bean id=splitterBean class=com.foo.MySplitterBean / My question is: How do I instantiate the splitterBean in my unit test so the route can access it ? And BTW, how do I do that for the errorReportingProcessor, which is also declared in the bundle-context.xml, too ? Many thanks in advance, Xavier -- View this message in context: http://camel.465427.n5.nabble.com/Camel-route-with-method-Unit-Testing-tp3370644p3370644.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel route with .method() - Unit Testing
Hi Using a registry. Map map = new HashMap(); map.put(beanId, beanInstance); this.context = new DefaultCamelContext(map); See details about registry in chapter 4 in the Camel book. Or google the website. There is also a ton of unit tests in camel-core you can take a look at, eg for the bean component. If you use the Camel test kit then you can override the createJndiContext method, which is automatic used by Camel if you dont instantiate a CamelContext yourself. protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind(foo, new FooBean()); answer.bind(bar, new BarBean()); answer.bind(baz, new BazBean()); return answer; } On Fri, Feb 4, 2011 at 9:57 AM, xdevroey xavier.devr...@atosorigin.com wrote: Hello, I am currently trying to write a unit test for a camel route which contains a .method(beanId,methodName) component: from(this.incomingSource) .split().method(splitterBean, splitMessages) .choice() .when(isValid) .marshal(jaxb).to(this.outgoingDestination) .otherwise() .processRef(errorReportingProcessor).to(this.invalidDestination) .end(); In the Test class I have the following lines for the @Before method : @Before public void beforeTest() throws Exception { this.context = new DefaultCamelContext(); this.route = new SplittingMainRoute(); this.route.setIncomingSource(mokc:in); this.route.setOutgoingDestination(mock:out); this.route.setInvalidDestination(mock:isValid); this.context.addRoutes(this.route); this.context.start(); this.producer = this.context.createProducerTemplate(); } I'm actually running Camel on Fuse-Servicemix and the splitterBean bean is defined in the bundle-context.xml as bean id=splitterBean class=com.foo.MySplitterBean / My question is: How do I instantiate the splitterBean in my unit test so the route can access it ? And BTW, how do I do that for the errorReportingProcessor, which is also declared in the bundle-context.xml, too ? Many thanks in advance, Xavier -- View this message in context: http://camel.465427.n5.nabble.com/Camel-route-with-method-Unit-Testing-tp3370644p3370644.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
Re: Camel route with .method() - Unit Testing
On Fri, Feb 4, 2011 at 10:01 AM, Claus Ibsen claus.ib...@gmail.com wrote: Hi Using a registry. Map map = new HashMap(); map.put(beanId, beanInstance); Ah was a bit to quick, you need to use SimpleRegistry instead of the Map. But it extends HashMap. this.context = new DefaultCamelContext(map); See details about registry in chapter 4 in the Camel book. Or google the website. There is also a ton of unit tests in camel-core you can take a look at, eg for the bean component. If you use the Camel test kit then you can override the createJndiContext method, which is automatic used by Camel if you dont instantiate a CamelContext yourself. protected Context createJndiContext() throws Exception { JndiContext answer = new JndiContext(); answer.bind(foo, new FooBean()); answer.bind(bar, new BarBean()); answer.bind(baz, new BazBean()); return answer; } On Fri, Feb 4, 2011 at 9:57 AM, xdevroey xavier.devr...@atosorigin.com wrote: Hello, I am currently trying to write a unit test for a camel route which contains a .method(beanId,methodName) component: from(this.incomingSource) .split().method(splitterBean, splitMessages) .choice() .when(isValid) .marshal(jaxb).to(this.outgoingDestination) .otherwise() .processRef(errorReportingProcessor).to(this.invalidDestination) .end(); In the Test class I have the following lines for the @Before method : @Before public void beforeTest() throws Exception { this.context = new DefaultCamelContext(); this.route = new SplittingMainRoute(); this.route.setIncomingSource(mokc:in); this.route.setOutgoingDestination(mock:out); this.route.setInvalidDestination(mock:isValid); this.context.addRoutes(this.route); this.context.start(); this.producer = this.context.createProducerTemplate(); } I'm actually running Camel on Fuse-Servicemix and the splitterBean bean is defined in the bundle-context.xml as bean id=splitterBean class=com.foo.MySplitterBean / My question is: How do I instantiate the splitterBean in my unit test so the route can access it ? And BTW, how do I do that for the errorReportingProcessor, which is also declared in the bundle-context.xml, too ? Many thanks in advance, Xavier -- View this message in context: http://camel.465427.n5.nabble.com/Camel-route-with-method-Unit-Testing-tp3370644p3370644.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ -- Claus Ibsen - FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
Re: Timers stop firing after certain unpredictable interval
Hi Do you see any exceptions in the log as the TimerConsumer does a try .. catch and logs the exception. } catch (Exception e) { getExceptionHandler().handleException(Error processing exchange, exchange, exchange.getException()); } My only thought could be that something more serious is thrown such as a Error which isn't caught. So we may have to use Throwable to ensure all is caught. On Fri, Feb 4, 2011 at 5:50 AM, s2010in samir.sum...@mphasis.com wrote: Hello, There is a issue with using timers, I have tried both timer and quartz timer to process a spring bean method using Camel 2.4.0 and Camel 2.6.0 on tomcat 6 container using spring Observation is timer stops processing after certain unpredictable interval, the service method is not getting called anymore, along with this all other routes also do not respond to events and messages keep piling up. This is causing entire processing to come at standstill unless server is restarted. If the timer route is removed things work well as they are supposed to be. Endpoint for Quartz: quartz://timerName?cron=0+*+18-8+?+*+MON-SAT Endpoint for Timer: timer://foo?fixedRate=trueperiod=6 Furthermore a smaller issue which has already been raised in this forum is these timers cause tomcat to hang and it wont shutdown gracefully. -- View this message in context: http://camel.465427.n5.nabble.com/Timers-stop-firing-after-certain-unpredictable-interval-tp3370457p3370457.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
Re: Camel route with .method() - Unit Testing
Hi Claus, It works fine ! Thanks, Xavier -- View this message in context: http://camel.465427.n5.nabble.com/Camel-route-with-method-Unit-Testing-tp3370644p3370740.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Dead Letter Error Handler and non blocking mode
Hi Claus, I upgraded to Camel 2.4 but I see still see blocking behavior. Here are the contents of my camel-context.xml. bean id=deadLetterErrorHandler class=org.apache.camel.builder.DeadLetterChannelBuilder !-- exchanges is routed to activemq:queue:ActiveMQ.DLQ in cased redelivery failed -- property name=deadLetterUri value=activemq:queue:ActiveMQ.DLQ / !-- reference the redelivery policy to use -- property name=redeliveryPolicy ref=redeliveryPolicyConfig / /bean !-- here we set the redelivery settings -- bean id=redeliveryPolicyConfig class=org.apache.camel.processor.RedeliveryPolicy !-- try redelivery at most 6 times, after that the exchange is dead and its routed to the activemq:queue:ActiveMQ.DLQ endpoint -- property name=maximumRedeliveries value=6 / !-- delay 300s before redelivery -- property name=redeliveryDelay value=30 / property name=asyncDelayedRedelivery value=true / /bean camelContext id=serviceContext trace=false xmlns=http://camel.apache.org/schema/spring; route id=calcQueue from uri=activemq:queue:Order / recipientList id=recipientList1 method method=calculate bean=queueCalculator / /recipientList /route route id=ProcessOrder errorHandlerRef=deadLetterErrorHandler from uri=activemq:queue:Order.* / bean ref=OrderProcessor method=process / /route /camelContext With above configuration if activemq:queue:Order.User1 is in retry mode, Camel doesn't process any messages from activemq:queue.Order.User2 queue. Camel waits to complete all retries in activemq:queue:Order.User1 before processing any message in activemq:queue.Order.User2 queue. Am I missing any configuration here? Thanks, Rahul -- View this message in context: http://camel.465427.n5.nabble.com/Dead-Letter-Error-Handler-and-non-blocking-mode-tp3361913p3371061.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Dead Letter Error Handler and non blocking mode
Hi See http://camel.465427.n5.nabble.com/Message-blocks-route-until-all-redelivery-attempts-are-exhausted-tp472319p472319.html On Fri, Feb 4, 2011 at 3:37 PM, rxm0203 rah_me...@yahoo.com wrote: Hi Claus, I upgraded to Camel 2.4 but I see still see blocking behavior. Here are the contents of my camel-context.xml. bean id=deadLetterErrorHandler class=org.apache.camel.builder.DeadLetterChannelBuilder !-- exchanges is routed to activemq:queue:ActiveMQ.DLQ in cased redelivery failed -- property name=deadLetterUri value=activemq:queue:ActiveMQ.DLQ / !-- reference the redelivery policy to use -- property name=redeliveryPolicy ref=redeliveryPolicyConfig / /bean !-- here we set the redelivery settings -- bean id=redeliveryPolicyConfig class=org.apache.camel.processor.RedeliveryPolicy !-- try redelivery at most 6 times, after that the exchange is dead and its routed to the activemq:queue:ActiveMQ.DLQ endpoint -- property name=maximumRedeliveries value=6 / !-- delay 300s before redelivery -- property name=redeliveryDelay value=30 / property name=asyncDelayedRedelivery value=true / /bean camelContext id=serviceContext trace=false xmlns=http://camel.apache.org/schema/spring; route id=calcQueue from uri=activemq:queue:Order / recipientList id=recipientList1 method method=calculate bean=queueCalculator / /recipientList /route route id=ProcessOrder errorHandlerRef=deadLetterErrorHandler from uri=activemq:queue:Order.* / bean ref=OrderProcessor method=process / /route /camelContext With above configuration if activemq:queue:Order.User1 is in retry mode, Camel doesn't process any messages from activemq:queue.Order.User2 queue. Camel waits to complete all retries in activemq:queue:Order.User1 before processing any message in activemq:queue.Order.User2 queue. Am I missing any configuration here? Thanks, Rahul -- View this message in context: http://camel.465427.n5.nabble.com/Dead-Letter-Error-Handler-and-non-blocking-mode-tp3361913p3371061.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
Re: Memory leak in camel mail component
Hi All, I am working together with Sri in a project which makes an extensive use of camel (you've seen some posts from me in the past). I can confirm the number of endpoints being created grows constantly using any protocol, with our system we are serving a very high number of endpoints and at the moment we are forced to restart our application every now and then to free up memory use. Is there a way to unreference all endpoints and therefore allow them to be deallocated by garbage collector? I think the issue described by Sri with mail component is a different problem as the leak is shown only when using recipient list, if we use a for cicle the memory use is not growing (hence the same endpoint is used). -- View this message in context: http://camel.465427.n5.nabble.com/Memory-leak-in-camel-mail-component-tp3364793p3371119.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Memory leak in camel mail component
On Fri, Feb 4, 2011 at 4:00 PM, Marco Crivellaro mcr...@optasportsdata.com wrote: Hi All, I am working together with Sri in a project which makes an extensive use of camel (you've seen some posts from me in the past). I can confirm the number of endpoints being created grows constantly using any protocol, with our system we are serving a very high number of endpoints and at the moment we are forced to restart our application every now and then to free up memory use. Is there a way to unreference all endpoints and therefore allow them to be deallocated by garbage collector? Are you using JMX? If so you can disable JMX then it ought to run. I think the problem is that endpoints gets enlisted in JMX and thus it grows. Camel itself just cache at most 1000 endpoints and thus it shouldn't be a big deal. That said I have though of only enlisting resources in JMX during starting a route. That ensures only static beans gets enlisted. Then all the dynamic endpoints and producers wont be enlisted. Although producers are not enlisted today. And many time you can put the dynamic parts of the endpoints as headers to the message. Frankly where it belong. Eg a To recipient in a mail message belongs as a message header, and not as an endpoint uri parameter. And keep the endpoint less dynamic. I think the issue described by Sri with mail component is a different problem as the leak is shown only when using recipient list, if we use a for cicle the memory use is not growing (hence the same endpoint is used). -- View this message in context: http://camel.465427.n5.nabble.com/Memory-leak-in-camel-mail-component-tp3364793p3371119.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - FuseSource Email: cib...@fusesource.com Web: http://fusesource.com Twitter: davsclaus Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
Re: Memory leak in camel mail component
Our system is built on top of the recipientList component and camel components URI parameters, we are using FTP, JMS, email and HTTP therefore we'd need a way to 'cleanup' the list of allocated endpoints, can't you provide a way of forcing endpoints list cleanup or perhaps customizing the maximum number of allowed endpoints in cache? You say it is not a big deal keeping 1000 endpoints in cache? would you have some numbers on how much they can occupy? We are investigating a possible memory leak in our application and therefore we are trying to isolate the issue. -- View this message in context: http://camel.465427.n5.nabble.com/Memory-leak-in-camel-mail-component-tp3364793p3371197.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Timers stop firing after certain unpredictable interval
Correct from 8:19 to 8:36 - Quartz is firing and timer seems working from tracer logs, it stops after 8:36 which it is not sure why, similar thing happens when timer is used from 8:19 to 8:26 - Bean method is called from camel route, after which even if timer is fired no bean method is called, there is no sought of exception in logs -- View this message in context: http://camel.465427.n5.nabble.com/Timers-stop-firing-after-certain-unpredictable-interval-tp3370457p3371213.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Camel webconsole in Karaf
I was working on adding this features, but have been unable to get it deployed properly (https://issues.apache.org/jira/browse/CAMEL-3519). If anyone has the steps to get this to work, let me know... - Ben O'Day IT Consultant -http://benoday.blogspot.com -- View this message in context: http://camel.465427.n5.nabble.com/Camel-webconsole-in-Karaf-tp3368226p3371232.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: camel-smpp - disconnect problem
Opened a ticket for it: https://issues.apache.org/jira/browse/CAMEL-3624 Add yourself as a watcher to track the progress...
Re: Camel webconsole in Karaf
I'll work on that, but I think that's actually a tricky issue. More on that later... On Friday, February 4, 2011, Bengt Rodehav be...@rodehav.com wrote: That looks a bit discouraging :-( Has this issues stopped completely then or is any progress being mad? /Bengt 2011/2/4 ben.oday ben.o...@initekconsulting.com I was working on adding this features, but have been unable to get it deployed properly (https://issues.apache.org/jira/browse/CAMEL-3519). If anyone has the steps to get this to work, let me know... - Ben O'Day IT Consultant -http://benoday.blogspot.com -- View this message in context: http://camel.465427.n5.nabble.com/Camel-webconsole-in-Karaf-tp3368226p3371232.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Guillaume Nodet Blog: http://gnodet.blogspot.com/ Open Source SOA http://fusesource.com
Re: Camel webconsole in Karaf
See my comment on the issue. On Fri, Feb 4, 2011 at 19:46, Guillaume Nodet gno...@gmail.com wrote: I'll work on that, but I think that's actually a tricky issue. More on that later... On Friday, February 4, 2011, Bengt Rodehav be...@rodehav.com wrote: That looks a bit discouraging :-( Has this issues stopped completely then or is any progress being mad? /Bengt 2011/2/4 ben.oday ben.o...@initekconsulting.com I was working on adding this features, but have been unable to get it deployed properly (https://issues.apache.org/jira/browse/CAMEL-3519). If anyone has the steps to get this to work, let me know... - Ben O'Day IT Consultant -http://benoday.blogspot.com -- View this message in context: http://camel.465427.n5.nabble.com/Camel-webconsole-in-Karaf-tp3368226p3371232.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Guillaume Nodet Blog: http://gnodet.blogspot.com/ Open Source SOA http://fusesource.com -- Cheers, Guillaume Nodet Blog: http://gnodet.blogspot.com/ Open Source SOA http://fusesource.com
Re: Dead Letter Error Handler and non blocking mode
Hi Claus, Thanks for the link. I think I am using similar approach. My first route calcQueue takes incoming message and puts it on a user specific queue (e.g. activemq:queue:Order.User1, activemq:queue:Order.User2) route id=calcQueue from uri=activemq:queue:WO / recipientList id=recipientList1 method method=calculate bean=queueCalculator / /recipientList /route OrderProcessor bean in second route ProcessOrder processes incoming messages on user specific queues (e.g. activemq:queue:Order.User1, activemq:queue:Order.User2) route id=ProcessOrder errorHandlerRef=deadLetterErrorHandler from uri=activemq:queue:Order.* / bean ref=OrderProcessor method=process / /route The issue is that when activemq:queue:Order.User1 is in retry mode, Camel doesn't process any messages from other user specific queues. I have redelivery delay of 5 minutes and it will increase in future. At present, Camel doesn't process any message for more than 30 minutes if one queue is blocking. My requirements are: 1) Messages should process in sequential order for each queue. This means that if activemq:queue:Order.User1 is in retry mode, none of the messages from activemq:queue:Order.User1 should process until redelivery attempts are exhausted. 2) When one queue is blocking in retry mode, Camel should continue to process messages in other user specific queues (e.g. activemq:queue:Order.User2, activemq:queue:Order.User3.) Do you think if I define one route per user specific queue then I can achieve above requirements? At present, I have only route defined with wild char character in it? I appreciate you help. Rahul -- View this message in context: http://camel.465427.n5.nabble.com/Dead-Letter-Error-Handler-and-non-blocking-mode-tp3361913p3371721.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Timers stop firing after certain unpredictable interval
Still not sure where the bug is, Used Camel timer, then Quartz timer, and finally created a separate TimerTask with java.util.Timer All of them do same, to get around have created my own daemon thread now which is working as I need to fire event after a fixed period. Please let me know if anyone has a fix -- View this message in context: http://camel.465427.n5.nabble.com/Timers-stop-firing-after-certain-unpredictable-interval-tp3370457p3372053.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Timers stop firing after certain unpredictable interval
Can you reproduce this consistently? Hadrian On Feb 4, 2011, at 7:15 PM, s2010in wrote: Still not sure where the bug is, Used Camel timer, then Quartz timer, and finally created a separate TimerTask with java.util.Timer All of them do same, to get around have created my own daemon thread now which is working as I need to fire event after a fixed period. Please let me know if anyone has a fix -- View this message in context: http://camel.465427.n5.nabble.com/Timers-stop-firing-after-certain-unpredictable-interval-tp3370457p3372053.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: camel-smpp - disconnect problem
On 02/04/2011 07:38 PM, Christian Müller wrote: Opened a ticket for it: https://issues.apache.org/jira/browse/CAMEL-3624 Add yourself as a watcher to track the progress... Thank you all for quick help!
Re: Timers stop firing after certain unpredictable interval
Finally while trying to reproduce the defect in testcase , I was able to nail down the problem, it would have been a easier fix if were not using new technologies, and old time classic code reviews would have helped Lets say we have route using Spring Route Builder from(timer://foo?fixedRate=trueperiod=6) .to(bean:testService?method=checkExchange) .to(jms:queue:test1); from(jms:queue:test1) .setHeader(Exchange.FILE_NAME, constant(received.xml)) .to(file:target/data/); Service testService, method checkExchange opens a org.apache.commons.dbcp.BasicDataSource based connection using Type 4 db2 driver and uses CallableStatement to call a stored procedure opening connection and callable statement each run. The code will stop timer after any unspecified number of runs, depending on free connections available and all routes become inoperative. The fix was indeed to close the connection and callable statement in finally block, a big miss but never predicted this will get all camel routes to standstill. Wondering why the separate thread approach worked for me, when all other timers failed, well this was something I had intentionally coded for reusing the Connection so it worked!! -- View this message in context: http://camel.465427.n5.nabble.com/Timers-stop-firing-after-certain-unpredictable-interval-tp3370457p3372178.html Sent from the Camel - Users mailing list archive at Nabble.com.