You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by weggyboy <wa...@gmail.com> on 2012/02/14 16:43:49 UTC

Reading all messages from ActiveMQ in pre defined interval

Hello,

I am trying to implement a camel solution for a pretty simple requirement.
Its about a monitoring system with jms. Here is what it looks like:

1. a process writes jms messages with an xml body in an activemq queue. The
xml body contains the monitoring data to be evaluated.
2. in a pre defined interval i wish to read ALL messages from that queue and
pass all the content to a bean processor.
3. the bean processor evaluates all the messages content and sends an e-mail
report to a pre defined mail address.

All my camel routes are being defined as xml. I prefer not to write any java
code but the bean processor.
Using a timer with pollEnrich of type jmsConsumer together with aggregator
did not work properly. Only one message could be read at time instead of
all.

<route>
    <from uri="timer://monitoringTimer&amp;period=600000" />
    <pollEnrich uri="jms:queue:monitoring"/>
    <aggregate strategyRef="aggregatorStrategy" completionTimeout="3000">
        <correlationExpression>
            <constant>true</contant>
        </correlationExpression>
        <to uri="bean:monitorEvaluator"/>
    </aggregate>
</route>

I was wondering if someone could give me some ideas on how to realize it
with camel.
Perhaps someone has any other better approach to solve this.
I would be very thankful ;)

Cheers,

Wagner



--
View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5482810.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Reading all messages from ActiveMQ in pre defined interval

Posted by Ashwin Karpe <ak...@fusesource.com>.
Sure thing... Glad I could help.

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5486724.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Reading all messages from ActiveMQ in pre defined interval

Posted by weggyboy <wa...@gmail.com>.
Hello Ashwin!
thanks a lot for your comment! I think with the ScheduledRoutePolicy I can
solve my problem :)
I really didn't know the routes have such a feature!
Awesome!

Thanks again ;)

--
View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5486407.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Reading all messages from ActiveMQ in pre defined interval

Posted by Ashwin Karpe <ak...@fusesource.com>.
Hi,

Have you taken a look at ScheduledRoutePolicy support in Camel
(CronScheduledRoutePolicy and/or SimpleScheduledRoutePolicy)

Depending on what your requirements are, you spin up and spin down routes as
if they were batch jobs on a given schedule.

http://camel.apache.org/scheduledroutepolicy.html
http://camel.apache.org/scheduledroutepolicy.html 

Hope this helps.

Cheers,

Ashwin...

-----
---------------------------------------------------------
Ashwin Karpe
Apache Camel Committer & Sr Principal Consultant
FUSESource (a Progress Software Corporation subsidiary)
http://fusesource.com 

Blog: http://opensourceknowledge.blogspot.com 
---------------------------------------------------------
--
View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5486336.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Reading all messages from ActiveMQ in pre defined interval

Posted by Matt Pavlovich <ma...@gmail.com>.
Good deal, let us know how it goes.  Just to clarify-- i was suggesting 
adding a completionSize in ADDITION to the completionInterval.  Its a 
"belt and suspenders" type approach.

On 2/14/12 12:12 PM, weggyboy wrote:
> Hi Matt,
>
> Thanks a lot for the quick answer.
> I guess, I found a solution. As you proposed, without the timer component.
> The aggregator component has a property called "completionInterval". In the
> documentation for this property it says:
> "/A repeating period in millis by which the aggregator will complete all
> current aggregated exchanges. Camel has a background task which is triggered
> every period.../"
>
> If I didn't misunderstand that, I think it is pretty much what I am looking
> for.
> I will be trying to use it and see what happens.
> As soon as I have new results, I post it here.
>
> Thanks again.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5483283.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Reading all messages from ActiveMQ in pre defined interval

Posted by weggyboy <wa...@gmail.com>.
Hi Matt,

Thanks a lot for the quick answer.
I guess, I found a solution. As you proposed, without the timer component.
The aggregator component has a property called "completionInterval". In the
documentation for this property it says:
"/A repeating period in millis by which the aggregator will complete all
current aggregated exchanges. Camel has a background task which is triggered
every period.../"

If I didn't misunderstand that, I think it is pretty much what I am looking
for.
I will be trying to use it and see what happens.
As soon as I have new results, I post it here.

Thanks again.



--
View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5483283.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Reading all messages from ActiveMQ in pre defined interval

Posted by Matt Pavlovich <ma...@gmail.com>.
I think you should consider reading from the queue directly, and remove 
the timing piece from the design altogether.  The beauty in this 
approach, is that it will be processing closer to realtime, and it will 
aggregate only when you need to aggregate.. in 3s batches.  If you only 
get one message every 5 minutes, there won't be any aggregating at all, 
but if you get a burst, then you will throttle traffic into the 
bean:monitorEvaluator by aggregating in 3s chunks.  You probably want to 
add a completionSize argument, so you'll cap your aggregation in terms 
of message count, as well as time.

<from uri="jms:queue:monitoring"/>
<aggregate ...>
     ..
<to uri="bean:monitorEvaluator"/>
</aggregate>

On 2/14/12 9:43 AM, weggyboy wrote:
> Hello,
>
> I am trying to implement a camel solution for a pretty simple requirement.
> Its about a monitoring system with jms. Here is what it looks like:
>
> 1. a process writes jms messages with an xml body in an activemq queue. The
> xml body contains the monitoring data to be evaluated.
> 2. in a pre defined interval i wish to read ALL messages from that queue and
> pass all the content to a bean processor.
> 3. the bean processor evaluates all the messages content and sends an e-mail
> report to a pre defined mail address.
>
> All my camel routes are being defined as xml. I prefer not to write any java
> code but the bean processor.
> Using a timer with pollEnrich of type jmsConsumer together with aggregator
> did not work properly. Only one message could be read at time instead of
> all.
>
> <route>
>      <from uri="timer://monitoringTimer&amp;period=600000" />
>      <pollEnrich uri="jms:queue:monitoring"/>
>      <aggregate strategyRef="aggregatorStrategy" completionTimeout="3000">
>          <correlationExpression>
>              <constant>true</contant>
>          </correlationExpression>
>          <to uri="bean:monitorEvaluator"/>
>      </aggregate>
> </route>
>
> I was wondering if someone could give me some ideas on how to realize it
> with camel.
> Perhaps someone has any other better approach to solve this.
> I would be very thankful ;)
>
> Cheers,
>
> Wagner
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Reading-all-messages-from-ActiveMQ-in-pre-defined-interval-tp5482810p5482810.html
> Sent from the Camel - Users mailing list archive at Nabble.com.