You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by hanson2010 <ha...@gmail.com> on 2010/11/18 11:07:30 UTC

Transaction configuration in Java DSL

What I'm trying to do is moving data from IBM MQ to ActiveMQ, and ensuring no
data lost during network failure or something like that. So TRANSACTION
comes into my mind. But I can't get it run in Java DSL. (Spring DSL will be
okay strangely.)

Camel 2.5.0
IBM MQ 7.0.1
ActiveMQ 5.4.1

CamelContext camel = new DefaultCamelContext();
...
JmsComponent wmq = JmsComponent.jmsComponentTransacted(mqConnectionFactory);
wmq.setTransactionManager(transactionManager);
camel.addComponent("wmq", wmq);
...
try {
	camel.addRoutes( new RouteBuilder() { 
		public void configure() { 
			errorHandler(new
TransactionErrorHandlerBuilder().maximumRedeliveries(-1));
			from("wmq:QL_TEST1")
			.transacted()
			.to("amq:TEST1");
			from("amq:TEST1").process(new Processor() {
				public void process(Exchange e) {
				System.out.println("Received exchange: " + e.getIn().getBody());
				}
			});
		} 
	}); 
	camel.start();
} catch (Exception e) {
	logger.error("Exception in camel: " + e.getMessage());
	return;
}

Error is like this:
[main] ERROR: Exception in camel: Failed to create route route1 at: >>>
Policy[ref:null] <<< in route: Route[[From[wmq:QL_TEST1]] ->
[Policy[ref:null]]] because of policy must be specified on: Policy[ref:null]

If I remove the .transacted() line, everything will be okay.

BTW, how can I configure the retry interval? During "network failure", the
error log file size surges really fast!

Thanks in ad!
-- 
View this message in context: http://camel.465427.n5.nabble.com/Transaction-configuration-in-Java-DSL-tp3270508p3270508.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Transaction configuration in Java DSL

Posted by hanson2010 <ha...@gmail.com>.
Thanks. I'll continue my investigation...

-----
--
Haisheng HU
http://hanson.appspot.com/
-- 
View this message in context: http://camel.465427.n5.nabble.com/Transaction-configuration-in-Java-DSL-tp3270508p3270852.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Transaction configuration in Java DSL

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Nov 18, 2010 at 2:42 PM, hanson2010 <ha...@gmail.com> wrote:
>
> Thank you Ibsen for following up my question so quickly, just after a dinner
> of me.
>
> Yes. I have done a test. It can rollback automatically after a failure. But
> I still have more confusions:
>
> 1) So do you mean JmsComponent.jmsComponentTransacted(...) is the key in my
> case? I just didn't find a description of the difference between JMS and
> JDBC resources, although it's just great the Chapter 9 is free to be
> downloaded.
>

Yeah the JMS component kinda have transaction build-in, where as JDBC
does not etc.
And if you use multiple ressources in the transaction you gotta do the
.transacted() in the route.




> 2) Actually I also need to move data reversely, from ActiveMQ to IBM MQ.
> Will it be possible I can put the 2 routes in one camel context?
> camel.addRoutes(...);
> camel.addRoutes(...);
>
> Or in one RouteBuilder()?
>

Yeah you can do whatever you want. Either use 1 RouteBuilder or use N
RouteBuilder.


> And should I declare both the origin and dest components TRANSACTED at the
> same time?
>

If you need AMQ and IBM to work in the same TX you need to use XA transactions.
And therefore you need a XA capable transaction manager.

Camel in Action chapter 9 covers XA transactions, however its a JMS ->
JDBC example.


> 3) During "network failure", the error log file size surges really fast (at
> every second). How can I configure the retry interval, and
> maximumRedeliveries, deadLetterChannel?
>

You have to configure this on the JMS broker because its the one who
re-deliver the message to Camel.

ActiveMQ have option for configuring this as well.


> Thanks!
> --
> View this message in context: http://camel.465427.n5.nabble.com/Transaction-configuration-in-Java-DSL-tp3270508p3270759.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Transaction configuration in Java DSL

Posted by hanson2010 <ha...@gmail.com>.
Thank you Ibsen for following up my question so quickly, just after a dinner
of me. 

Yes. I have done a test. It can rollback automatically after a failure. But
I still have more confusions:

1) So do you mean JmsComponent.jmsComponentTransacted(...) is the key in my
case? I just didn't find a description of the difference between JMS and
JDBC resources, although it's just great the Chapter 9 is free to be
downloaded.

2) Actually I also need to move data reversely, from ActiveMQ to IBM MQ.
Will it be possible I can put the 2 routes in one camel context?
camel.addRoutes(...);
camel.addRoutes(...);

Or in one RouteBuilder()?

And should I declare both the origin and dest components TRANSACTED at the
same time?

3) During "network failure", the error log file size surges really fast (at
every second). How can I configure the retry interval, and
maximumRedeliveries, deadLetterChannel?

Thanks!
-- 
View this message in context: http://camel.465427.n5.nabble.com/Transaction-configuration-in-Java-DSL-tp3270508p3270759.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Transaction configuration in Java DSL

Posted by Claus Ibsen <cl...@gmail.com>.
Transaction is done using Spring Transaction, so you need to configure
some spring pieces for this to work.

However in your case you are only using JMS you can in fact just
configure it to be transacted, and dont use the .transacted() in the
route.
The JMS will still commit/rollback because it can do that.

However if you add eg JDBC in the Camel route, you need the
.transacted() in the route.

Check out chapter 9 in the Camel book.

Also the Transactional Client EIP pattern covers transaction
http://camel.apache.org/transactional-client.html


On Thu, Nov 18, 2010 at 11:07 AM, hanson2010 <ha...@gmail.com> wrote:
>
> What I'm trying to do is moving data from IBM MQ to ActiveMQ, and ensuring no
> data lost during network failure or something like that. So TRANSACTION
> comes into my mind. But I can't get it run in Java DSL. (Spring DSL will be
> okay strangely.)
>
> Camel 2.5.0
> IBM MQ 7.0.1
> ActiveMQ 5.4.1
>
> CamelContext camel = new DefaultCamelContext();
> ...
> JmsComponent wmq = JmsComponent.jmsComponentTransacted(mqConnectionFactory);
> wmq.setTransactionManager(transactionManager);
> camel.addComponent("wmq", wmq);
> ...
> try {
>        camel.addRoutes( new RouteBuilder() {
>                public void configure() {
>                        errorHandler(new
> TransactionErrorHandlerBuilder().maximumRedeliveries(-1));
>                        from("wmq:QL_TEST1")
>                        .transacted()
>                        .to("amq:TEST1");
>                        from("amq:TEST1").process(new Processor() {
>                                public void process(Exchange e) {
>                                System.out.println("Received exchange: " + e.getIn().getBody());
>                                }
>                        });
>                }
>        });
>        camel.start();
> } catch (Exception e) {
>        logger.error("Exception in camel: " + e.getMessage());
>        return;
> }
>
> Error is like this:
> [main] ERROR: Exception in camel: Failed to create route route1 at: >>>
> Policy[ref:null] <<< in route: Route[[From[wmq:QL_TEST1]] ->
> [Policy[ref:null]]] because of policy must be specified on: Policy[ref:null]
>
> If I remove the .transacted() line, everything will be okay.
>
> BTW, how can I configure the retry interval? During "network failure", the
> error log file size surges really fast!
>
> Thanks in ad!
> --
> View this message in context: http://camel.465427.n5.nabble.com/Transaction-configuration-in-Java-DSL-tp3270508p3270508.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/