Return-Path: Delivered-To: apmail-camel-users-archive@www.apache.org Received: (qmail 58993 invoked from network); 24 Mar 2009 14:02:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Mar 2009 14:02:26 -0000 Received: (qmail 79720 invoked by uid 500); 24 Mar 2009 14:02:26 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 79697 invoked by uid 500); 24 Mar 2009 14:02:26 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 79687 invoked by uid 99); 24 Mar 2009 14:02:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Mar 2009 14:02:25 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of james.strachan@gmail.com designates 209.85.218.226 as permitted sender) Received: from [209.85.218.226] (HELO mail-bw0-f226.google.com) (209.85.218.226) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Mar 2009 14:02:17 +0000 Received: by bwz26 with SMTP id 26so2221321bwz.20 for ; Tue, 24 Mar 2009 07:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :received:message-id:subject:from:to:content-type :content-transfer-encoding; bh=o00KDat69k6pogxe+bs0gXOW2fyArlBvnhHskLYlwt8=; b=u+Nyk9rQ8ilzM9muenZQOZz9IKyatnz3t8sCVeCGNlEORQnMP6zMyY7MabQ7dY0aJM 8M2fCvieyny4FV6nSt9rstzGMHpA2uIO8ZM0iCV3NviVByqjwufTEEpawNHowaIzCmOx SRc/5iStEzUFRUMuxOAxqKfMvwgci5U58Ay/s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=CjeNaJbrusBciqssFrh6NpMRdXMT+WI+KPXcCufJykQCd8getyZi9cFD9YRMOU2Bel QFhTnt3S/NvO8mGs7NBPK0qFerUp+QIUu4RDlbnaVKMbPHXF+lmphW4subSlMfFS129y PrTaKGlkfGZFNcPNJkLbdxJ3sMcUW3L3CP+1A= MIME-Version: 1.0 In-Reply-To: <49C8E620.4070507@attglobal.net> References: <49C7B384.7040609@attglobal.net> <5380c69c0903231125q6ccf7215h6ee93a7335ca07ac@mail.gmail.com> <49C7DF43.2010100@attglobal.net> <49C8DDE5.9020508@attglobal.net> <49C8E620.4070507@attglobal.net> Date: Tue, 24 Mar 2009 14:01:40 +0000 Received: by 10.223.105.75 with SMTP id s11mr7128564fao.4.1237903315467; Tue, 24 Mar 2009 07:01:55 -0700 (PDT) Message-ID: Subject: Re: Non-Spring Transaction Manager From: James Strachan To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org I think the issue is that you configure the configuration of the JMS component with the transaction manager after you've created the JMS endpoint. Try moving the configuration of the JMS component to the setup method; before you create any endpoints? 2009/3/24 Colin Ruthven : > Thought you'd ask. :) > It reflects some exploration of a couple of Camel API's, rather than bein= g > stripped to a minimum. > > Thanks again for helping. > Colin > > public class DataCamelTest extends TestCase{ > =A0 CamelContext context; > > =A0 ProducerTemplate prod; > =A0 Endpoint end; > =A0 =A0 public DataCamelTest(String arg0) { > =A0 =A0 =A0 super(arg0); > =A0 } > > =A0 protected void setUp() throws Exception { > =A0 =A0 =A0 super.setUp(); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 context =3D new DefaultCamelConte= xt(); > =A0 =A0 =A0 context.start(); > =A0 =A0 =A0 context.addComponent("activemq", > =A0 =A0 =A0 ActiveMQComponent.activeMQComponent("tcp://localhost:61616"))= ; > > =A0 =A0 =A0 prod =3D new DefaultProducerTemplate(context); > =A0 =A0 =A0 end =3D context.getComponent("activemq").createEndpoint("TEST= .FOO"); > =A0 =A0 =A0 context.addEndpoint("end", end ); > =A0 } > > =A0 public void testProcess() throws InterruptedException { > =A0 =A0 =A0 //System.out.println(producer); > =A0 =A0 =A0 //assertTrue(producer!=3Dnull); > > =A0 =A0 =A0 ApplicationContext spring =3D new > ClassPathXmlApplicationContext("applicationContext.xml"); > =A0 =A0 =A0 JtaTransactionManager transactionManager =3D (JtaTransactionM= anager) > spring.getBean("jtaTransactionManager"); > =A0 =A0 =A0 ((JmsComponent) > context.getComponent("activemq")).getConfiguration().setTransactionManage= r(transactionManager); > =A0 =A0 =A0 ((JmsComponent) > context.getComponent("activemq")).getConfiguration().setTransacted(true); > > =A0 =A0 =A0 Transaction tx =3D null; > =A0 =A0 =A0 Jotm jotm =3D null; > =A0 =A0 =A0 TransactionManager tm =3D null; > =A0 =A0 =A0 try { > =A0 =A0 =A0 =A0 =A0 jotm =3D new Jotm(true, false); > =A0 =A0 =A0 =A0 =A0 tm =3D jotm.getTransactionManager(); > =A0 =A0 =A0 =A0 =A0 tm.begin(); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 prod.sendBody( > "activemq:TEST.FOO", "Hello"); > =A0 =A0 =A0 =A0 =A0 prod.sendBody( end, "Hello1"); > > =A0 =A0 =A0 =A0 =A0 tm.rollback(); > > =A0 =A0 =A0 } catch (IllegalStateException e1) { > =A0 =A0 =A0 =A0 =A0 e1.printStackTrace(); > =A0 =A0 =A0 } catch (SystemException e1) { > =A0 =A0 =A0 =A0 =A0 e1.printStackTrace(); > =A0 =A0 =A0 } catch (NamingException e) { > =A0 =A0 =A0 =A0 =A0 e.printStackTrace(); > =A0 =A0 =A0 } catch (NotSupportedException e) { > =A0 =A0 =A0 =A0 =A0 e.printStackTrace(); > =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0 =A0 Endpoint endpoint =3D context.getEndpoint("active= mq:TEST.FOO"); > =A0 =A0 =A0 Consumer consumer =3D null; > > =A0 =A0 =A0 Processor my =3D new MyProcessor(); > =A0 =A0 =A0 try { > =A0 =A0 =A0 =A0 =A0 consumer =3D endpoint.createConsumer(my); > =A0 =A0 =A0 =A0 =A0 consumer.start(); =A0 =A0 =A0 } catch (Exception e) { > =A0 =A0 =A0 =A0 =A0 e.printStackTrace(); > =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0 =A0 try { > =A0 =A0 =A0 =A0 =A0 Thread.sleep(1000000); > =A0 =A0 =A0 } catch (InterruptedException e) { > =A0 =A0 =A0 =A0 =A0 e.printStackTrace(); > =A0 =A0 =A0 } > =A0 } > > =A0 public static class MyProcessor implements Processor { > =A0 =A0 =A0 private int count; > =A0 =A0 =A0 public void process(Exchange exchange) throws Exception { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Messa= ge message =3D exchange.getIn(); > =A0 =A0 =A0 =A0 =A0 =A0 System.out.println(message.getBody()); =A0 =A0 = =A0 =A0 } > =A0 } > } > > > James Strachan wrote: >> >> Whats the code using the producer look like? >> >> 2009/3/24 Colin Ruthven : >> >>> >>> Thanks. That got me further. >>> >>> Assuming I use JOTM and use it for transaction control within Java, I >>> attempted the following applicationContext.xml : >>> >>> =A0 >>> =A0 >>> =A0 >>> >>> =A0>> class=3D"org.springframework.transaction.jta.JotmFactoryBean"/> >>> >>> =A0>> class=3D"org.springframework.transaction.jta.JtaTransactionManager"> >>> =A0 =A0 >>> =A0 >>> >>> =A0>> class=3D"org.apache.activemq.spring.ActiveMQXAConnectionFactory"> >>> >>> =A0 =A0>> class=3D"org.apache.camel.component.jms.JmsComponent"> >>> =A0 =A0 =A0>> local=3D"jtaTransactionManager"/> >>> =A0 =A0 =A0 >>> =A0 =A0 =A0>> local=3D"jmsConnectionFactory"/> >>> >>> =A0 >>> >>> I have a unit test successfully sending and receiving to an ActiveMQ >>> broker >>> outside the VM. >>> >>> To that test I created a JOTM TransactionManager, Transaction then >>> prefixed >>> the producer.sendBody() with a begin transaction and followed the send >>> with >>> a rollback. >>> The message still gets sent. >>> >>> By the looks of stdout Spring is finding the JTA and JOTM is starting. >>> >>> I'm using Camel 1.6 and ActiveMQ 5.2 >>> >>> What am I missing? >>> >>> Thanks, >>> Colin >>> >>> James Strachan wrote: >>> >>>> >>>> 2009/3/23 Colin Ruthven : >>>> >>>> >>>>> >>>>> I don't specifically have one in mind. >>>>> >>>>> In exploring Camel I found that one can perform the basic messaging >>>>> functions in Java using Camel API's only but got messy with >>>>> transactions. >>>>> >>>>> My preference would be for Camel to expose a JTA. If that transparent= ly >>>>> invoked Spring TX that would be fine - analogous to the various >>>>> components >>>>> wrapping Spring but not exposing it directly in Java. >>>>> >>>>> >>>> >>>> BTW you can ignore the Spring IoC stuff if you like and just use Java >>>> to wire stuff together and populate JNDI - or use Guice or whatever. >>>> >>>> >>>> >>>> >>>>> >>>>> What other options exist outside a container (or inside) for >>>>> transaction >>>>> support that would work with Camel? >>>>> >>>>> >>>> >>>> The JMS component & endpoints relies on the Spring JMS abstractions >>>> (JmsTemplate and MessageListenerContainer classes) which use Spring >>>> transactions under the covers. However its pretty trivial to configure >>>> the JmsComponent to use Spring's JtaTransactionManager then you can do >>>> whatever you like with JTA and all the JMS endpoints will be >>>> auto-enlisted in JTA for you. >>>> >>>> However one of the main benefits of the spring transactions support >>>> (other than the proxy/aop/annotation stuff) is that its trivial to >>>> switch between XA/JTA and =A0lightweight transactions (e.g. pure JMS >>>> transactions or pure JDBC transactions) without the J2EE Transaction >>>> Manager / JCA / XA overhead. >>>> >>>> >>>> >> >> >> >> > --=20 James ------- http://macstrac.blogspot.com/ Open Source Integration http://fusesource.com/