On Wed, May 13, 2009 at 1:34 PM, sbuster <[email protected]> wrote: > > I'm new to Camel and I would like some input on the following code I am > trying to write. Hi
Welcome on the Camel rider :) > > Messages arrives on a Queue, and from that queue i would like to open the > message, determine if the message id already exists in a database table, and > if it does then discard the message. If it does not, then add the message > to the database table. > > Would I use a Processor to do the check against the table? > Can I use the JDBC component to do the check, I'm assuming I can use it to > do the insert > How would I stop the route if the record already exist, ie, not continue to > the "insert" endpoint? If you think EIP patterns then there is the filter EIP that is used for dropping unwanted messages. http://camel.apache.org/message-filter.html So the next step would how do we tell the filter if its green or red light? eg true or false. You can do this as regular POJO. Eg create a regular Class that has a method that returns a boolean. Then you route can be: from('jms:queue:myqueue') .filter().method(MyBean.class, "myMethod") .to('database insert endpoint?') Where MyBean is your POJO. If you use Spring XML for defining beans etc. Then you can refer to a spring bean by its id .filter().method("myBeanId", "myMethod") And with Spring XML you can dependency inject your bean to get a DataSource so you can do some SQL to test whether the message exists or not. The signature of your method can be kinda anything as Camel uses Bean Binding. http://camel.apache.org/bean-binding.html So if the JMS payload is String based you can just define it as boolean myMethod(String body) { // do some SQL to see if the message exists return true or false; } > > would it look something like this > from('jms:queue:myqueue').to(????).to('database insert endpoint?') > > > Thanks in advance! > Steve > > -- > View this message in context: > http://www.nabble.com/Simple-Routing-Example-tp23520058p23520058.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 Apache Camel Reference Card: http://refcardz.dzone.com/refcardz/enterprise-integration Interview with me: http://architects.dzone.com/articles/interview-claus-ibsen-about?mz=7893-progress
