You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Patrick Daly <pa...@daly.ws> on 2011/04/26 17:26:06 UTC
Transactional jms
Hi
Using Apache camel 2.7
I've taken a simple example from the Camel in Action book.
chapter9\multiple-routes
An modified it slighly.
from("activemq:queue:a")
.transacted()
.to("bean:process?method=process");
public class Process {
protected ProducerTemplate template;
public void process(Exchange exchange) throws InterruptedException{
System.out.println(exchange);
for (int i = 0; i<2; i++){
if(i == 1){
throw new InterruptedException();
}
System.out.println("************************ producer is " +
template);
template.send("activemq:queue:b", exchange);
}
}
public void setTemplate(ProducerTemplate template) {
this.template = template;
}
}
I see that the transaction rolls back and a message remains on the queue:a
after the interruptionException is thrown,
however the message that is sent to queue:b is not rolled back.
To explain a little more on my issue. We have a trigger message on a queue
that is then processed by a bean.
This bean goes to the database and publishes many messages onto another
queue for extra processing.One for each row in the database.
If we have a failure, I dont what to send the same message onto the second
queue.
Hope someone can help.
Otherwise I was thinking of keeping a message repository of messages I've
already published.
Re: Transactional jms
Posted by Patrick Daly <pa...@daly.ws>.
Thank you Willem for your response.
In my example I have a message that arrives on queue:a and then is routed to
bean:process.
If I didnt thown an Interrupt exception in the class the result would be 2
messages on queue:b.
I wanted to see what would happen if something went wrong i.e (computer
crash) while Process class was in the middle of processing.
So I generated an exception on the second message. (i == 1).
When I look at the queues. I see a message on queue:a and 1 message on
queue:b.
I'm expecting that if I launch the application again, this time commenting
out the interrupt exception.
At the end of the route there would be 3 messages on queue:b.
I'm wondering if it is possible to have a gobal transaction around the
entire route that includes any message published by the producerTemplate, so
if something goes wrong all routes are rolled back.
On Wed, Apr 27, 2011 at 1:47 AM, Willem Jiang <wi...@gmail.com>wrote:
> Hi
>
> You are using the producer template to send the message to a queue, in this
> case the transaction error handler will not be triggered.
>
> BTW, when the interruptedException is thrown, the template will not send
> the message to the queue:b. I don't get you description of the message that
> is sent to queue:b is not rolled back.
>
> If you don't want to send the same message again, you may take a look at
> the DeadLetterChannel[1]
>
> [1]http://camel.apache.org/dead-letter-channel.html
>
> Willem
>
> On 4/26/11 11:26 PM, Patrick Daly wrote:
>
>> Hi
>>
>> Using Apache camel 2.7
>>
>> I've taken a simple example from the Camel in Action book.
>> chapter9\multiple-routes
>>
>>
>>
>> An modified it slighly.
>>
>> from("activemq:queue:a")
>> .transacted()
>> .to("bean:process?method=process");
>>
>>
>> public class Process {
>> protected ProducerTemplate template;
>>
>> public void process(Exchange exchange) throws InterruptedException{
>> System.out.println(exchange);
>>
>> for (int i = 0; i<2; i++){
>>
>> if(i == 1){
>> throw new InterruptedException();
>> }
>> System.out.println("************************ producer is " +
>> template);
>> template.send("activemq:queue:b", exchange);
>>
>> }
>> }
>>
>> public void setTemplate(ProducerTemplate template) {
>> this.template = template;
>> }
>> }
>>
>>
>> I see that the transaction rolls back and a message remains on the queue:a
>> after the interruptionException is thrown,
>> however the message that is sent to queue:b is not rolled back.
>>
>> To explain a little more on my issue. We have a trigger message on a queue
>> that is then processed by a bean.
>> This bean goes to the database and publishes many messages onto another
>> queue for extra processing.One for each row in the database.
>>
>> If we have a failure, I dont what to send the same message onto the second
>> queue.
>> Hope someone can help.
>>
>> Otherwise I was thinking of keeping a message repository of messages I've
>> already published.
>>
>>
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>
> Connect at CamelOne May 24-26
> The Open Source Integration Conference
> http://camelone.com
>
Re: Transactional jms
Posted by Willem Jiang <wi...@gmail.com>.
Hi
You are using the producer template to send the message to a queue, in
this case the transaction error handler will not be triggered.
BTW, when the interruptedException is thrown, the template will not
send the message to the queue:b. I don't get you description of the
message that is sent to queue:b is not rolled back.
If you don't want to send the same message again, you may take a look at
the DeadLetterChannel[1]
[1]http://camel.apache.org/dead-letter-channel.html
Willem
On 4/26/11 11:26 PM, Patrick Daly wrote:
> Hi
>
> Using Apache camel 2.7
>
> I've taken a simple example from the Camel in Action book.
> chapter9\multiple-routes
>
>
>
> An modified it slighly.
>
> from("activemq:queue:a")
> .transacted()
> .to("bean:process?method=process");
>
>
> public class Process {
> protected ProducerTemplate template;
>
> public void process(Exchange exchange) throws InterruptedException{
> System.out.println(exchange);
>
> for (int i = 0; i<2; i++){
>
> if(i == 1){
> throw new InterruptedException();
> }
> System.out.println("************************ producer is " +
> template);
> template.send("activemq:queue:b", exchange);
>
> }
> }
>
> public void setTemplate(ProducerTemplate template) {
> this.template = template;
> }
> }
>
>
> I see that the transaction rolls back and a message remains on the queue:a
> after the interruptionException is thrown,
> however the message that is sent to queue:b is not rolled back.
>
> To explain a little more on my issue. We have a trigger message on a queue
> that is then processed by a bean.
> This bean goes to the database and publishes many messages onto another
> queue for extra processing.One for each row in the database.
>
> If we have a failure, I dont what to send the same message onto the second
> queue.
> Hope someone can help.
>
> Otherwise I was thinking of keeping a message repository of messages I've
> already published.
>
--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Connect at CamelOne May 24-26
The Open Source Integration Conference
http://camelone.com