tags:

views:

32

answers:

1

my camel route is given below

 <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring" >
    <route>
      <from uri="bean:SendClass?method=send" />
      <to uri="jms:MyQueue" pattern="InOnly" />
    </route>
    <route>
    <from uri="jms:MyQueue" />
    <to uri="bean:recvClass?method=recv" />
    </route>
  </camelContext>

The send method sends messages when activated by a 3rd party Pojo at some irregular intervals.But, the problem i think is camel is restarting the routes once the message is being received by recv bean and resending the same message (hundred's of them in a second ) .Ideally i want it to send the message when the send method gets activated and a new message has been created (i.e JMS Queue should be having unique message's).how do i do this ?

possible solutions being:

  1. is their some attribute which i can place inside the <from.../> to do this ?
  2. write a processor to filter unique message's between the send bean and the queue .
  3. Is their some other way of routing it without using the <from uri="bean:..." />

thanks sanre6

A: 

You should not have the 1st route. When you do that you tell Camel to constantly invoke the send method on that bean and route it. And hence why you see 100s of messages per sec.

Instead you should use some Camel API from within your bean code and send the message to the JMS queue. For example using a ProducerTemplate.

Claus Ibsen
I am of the opinion that i can either use Spring XMl or Java DSl at one time . So , if i use Producertemplate like template.sendBody("activemq:MyQueue", "<hello>world!</hello>");....then it means i have to use Java DSl right? how can i do that with a Spring XML. thanks for the answer
sanre6
In the Java code of the send() method. This is where you send the message to Camel, because then it happens when the send() method has been invoked.
Claus Ibsen
See for example: http://camel.apache.org/pojo-producing.html
Claus Ibsen
is there a way i can do it directly in the camelcontext xml file,without using the annotation's in java code ?
sanre6
You can hide the middleware. See my answer in one of your other questions.
Claus Ibsen