You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bxkrish <ba...@gmail.com> on 2010/10/04 02:33:02 UTC

Camel Aggregation : All Messages Lost from the Queue.

Hi 

I am using Camel 2.0. I am trying to do a simple aggregation of messages
dropped in one Queue to another Queue. 

For Example: Q1 = 1,2,3,4...10 messages, I want it to be 1 message in Q2
which is concatenation of (1,2,3, 4...10). 

I do not have any specific Correlation Expression, hence just creating a
Constant Header. 

Below is my configuration from Camel Context. 

<camelContext trace="false" id="EIP_CamelConext"
xmlns="http://camel.apache.org/schema/spring"> 
        <route> 
          <from uri="jms:Q1" /> 
          <setHeader headerName="Test"> 
             <constant>Yes</constant> 
          </setHeader> 
          <aggregator strategyRef="aggregatorStrategy"> 
           <correlationExpression> 
             <simple>header.Test</simple> 
           </correlationExpression>	  	   
          <to uri="jms:Q2"/> 
          </aggregator> 
        </route> 
</camelContext> 
<bean id="aggregatorStrategy"
class="com.aggregation.strategy.MessageAggregation"/> 

//JAVA Code for custom Aggregation Strategy. 
public class MessageAggregation implements AggregationStrategy{ 
        public Exchange aggregate(Exchange oldExchange, Exchange
newExchange) { 
                System.out.println("Here"); 
                Message newIn = newExchange.getIn(); 
                String oldBody = oldExchange.getIn().getBody(String.class); 
                String newBody = newIn.getBody(String.class); 
                newIn.setBody(oldBody + newBody); 
                return newExchange; 
        } 
} 

At runtime the messages are getting cleared from Q1 and nothing is available
on Q2. I can see the MessageAggregation is getting called. 

Please help. 

Thanks 
Bala 
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-Aggregation-All-Messages-Lost-from-the-Queue-tp3138936p3138936.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Aggregation : All Messages Lost from the Queue.

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Oct 5, 2010 at 7:11 PM, bxkrish <ba...@gmail.com> wrote:
>
> Thanks Claus. I am able to see the message aggregated. I have one another
> question. I need to do this aggregation at certain time of the day. Is it
> possible to configure that with Camel 2.0. Does it support "quartz" timer.
> If not, is there an alternative available?

You could start/stop the route depending on the quartz timer. There is
API on CamelContext to start/stop routes.
In Camel 2.0 you will have to do this by yourself.

In Camel 2.x you can use a route policy
http://camel.apache.org/routepolicy.html

For example in Camel 2.5 we are adding the scheduled routing policy.

> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Aggregation-All-Messages-Lost-from-the-Queue-tp3138936p3199998.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Camel Aggregation : All Messages Lost from the Queue.

Posted by bxkrish <ba...@gmail.com>.
Thanks Claus. I am able to see the message aggregated. I have one another
question. I need to do this aggregation at certain time of the day. Is it
possible to configure that with Camel 2.0. Does it support "quartz" timer.
If not, is there an alternative available?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-Aggregation-All-Messages-Lost-from-the-Queue-tp3138936p3199998.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Aggregation : All Messages Lost from the Queue.

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Oct 5, 2010 at 1:16 AM, bxkrish <ba...@gmail.com> wrote:
>
> Thanks for the reply Claus. Camel 2.0 is part of our product version and we
> will not be able to change it without releasing a different version of our
> product. I am sure 2.4 is a more stable version but Aggregation should be
> working with Camel 2.0.
> I debugged and found that the "oldExchange" is null "always" and not only
> for the first time. After handling the NullPointerException the messages
> reach the Q2 individually. However I want them to be concatenated as 1
> message. Can you please tell me what am I doing wrong?

See the wiki page
http://camel.apache.org/aggregator

You may need to set a higher batchTimeout than the default of 1 sec.
This allows Camel more time to aggregate more messages.


> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Aggregation-All-Messages-Lost-from-the-Queue-tp3138936p3198589.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Camel Aggregation : All Messages Lost from the Queue.

Posted by bxkrish <ba...@gmail.com>.
Thanks for the reply Claus. Camel 2.0 is part of our product version and we
will not be able to change it without releasing a different version of our
product. I am sure 2.4 is a more stable version but Aggregation should be
working with Camel 2.0.
I debugged and found that the "oldExchange" is null "always" and not only
for the first time. After handling the NullPointerException the messages
reach the Q2 individually. However I want them to be concatenated as 1
message. Can you please tell me what am I doing wrong?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-Aggregation-All-Messages-Lost-from-the-Queue-tp3138936p3198589.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Aggregation : All Messages Lost from the Queue.

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Oct 4, 2010 at 2:33 AM, bxkrish <ba...@gmail.com> wrote:
>
> Hi
>
> I am using Camel 2.0. I am trying to do a simple aggregation of messages
> dropped in one Queue to another Queue.
>
> For Example: Q1 = 1,2,3,4...10 messages, I want it to be 1 message in Q2
> which is concatenation of (1,2,3, 4...10).
>
> I do not have any specific Correlation Expression, hence just creating a
> Constant Header.
>
> Below is my configuration from Camel Context.
>
> <camelContext trace="false" id="EIP_CamelConext"
> xmlns="http://camel.apache.org/schema/spring">
>        <route>
>          <from uri="jms:Q1" />
>          <setHeader headerName="Test">
>             <constant>Yes</constant>
>          </setHeader>
>          <aggregator strategyRef="aggregatorStrategy">
>           <correlationExpression>
>             <simple>header.Test</simple>
>           </correlationExpression>
>          <to uri="jms:Q2"/>
>          </aggregator>
>        </route>
> </camelContext>
> <bean id="aggregatorStrategy"
> class="com.aggregation.strategy.MessageAggregation"/>
>
> //JAVA Code for custom Aggregation Strategy.
> public class MessageAggregation implements AggregationStrategy{
>        public Exchange aggregate(Exchange oldExchange, Exchange
> newExchange) {
>                System.out.println("Here");
>                Message newIn = newExchange.getIn();
>                String oldBody = oldExchange.getIn().getBody(String.class);
>                String newBody = newIn.getBody(String.class);
>                newIn.setBody(oldBody + newBody);
>                return newExchange;
>        }
> }
>
> At runtime the messages are getting cleared from Q1 and nothing is available
> on Q2. I can see the MessageAggregation is getting called.
>

Is there a reason why you use the old Camel 2.0 release? If possible
upgrade to the latest stable release which is 2.4.

Anyway make sure that you don't throw an exceptions from your custom
MessageAggregation code.
That could potential cause the aggregated message not to complete and send to Q2



> Please help.
>
> Thanks
> Bala
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Aggregation-All-Messages-Lost-from-the-Queue-tp3138936p3138936.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Could UnitOfWork support a customed transaction-like processs?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

See chapter 9 in the Camel in action book which talks about "compensations"
It shows how you can rollback/commit a file etc. And lays out how you
can do this as well for custom endpoints / components etc.



On Fri, Oct 8, 2010 at 6:56 AM, ext2 <xu...@tongtech.com> wrote:
> Hi:
>        Only transactional resources(Database, JMS etc) could support
> transaction. While other resources( File etc) couldn't support transaction.
>        Doest the camel support a feature to support a custom transaction
> process? The feature allow we write custom commit/rollback process for an
> endpoint, and when the camel-route finished, all the executed endpoints'
> custom commit/rollback method will be called.
>        It seems the UnitOfWork  of Camel can do this, could it?
>
> Thanks any suggestion
>
>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Could UnitOfWork support a customed transaction-like processs?

Posted by ext2 <xu...@tongtech.com>.
Hi:
	Only transactional resources(Database, JMS etc) could support
transaction. While other resources( File etc) couldn't support transaction.
	Doest the camel support a feature to support a custom transaction
process? The feature allow we write custom commit/rollback process for an
endpoint, and when the camel-route finished, all the executed endpoints'
custom commit/rollback method will be called.
	It seems the UnitOfWork  of Camel can do this, could it?

Thanks any suggestion