Hi Antonin. Thanks for the response.
I attempted a naive implementation of TransactionServices and it appears to load via the serviceloader correctly, and produce UserTransactions: https://github.com/garyhodgson/camel-example-cdi-standalone-jta/blob/TransactionServices/src/main/java/org/apache/camel/example/cdi/util/TransactionServices.java Sadly the AtomikosTransactionRequiredJMSException is still thrown. On 6 November 2017 at 11:52, Antonin Stefanutti <anto...@stefanutti.fr> wrote: > Hi Gary, > > Your CDI producers for the ActiveMQ component and the transaction manager > look OK (aside that you would have to destroy the connection factory in a > dispose method). > > However The way you produce the UserTransaction may be problematic. With > Weld SE, you would typically implement > org.jboss.weld.transaction.spi.TransactionServices > and add it as a Weld service before starting the CDI container. > > Let me know if that helps. > > Antonin > > > On 5 Nov 2017, at 21:54, Gary Hodgson <gary.s.hodg...@gmail.com> wrote: > > > > Hi, > > > > I am trying to get camel-cdi to work with a standalone JTA provider in a > > non-JEE environment. I've made some progress but have a couple of issues > > which I am not sure is due to my understanding or the code. > > > > I created a standalone demo project here to show the issues: > > https://github.com/garyhodgson/camel-example-cdi-standalone-jta > > > > The demo uses Atomikos as the JTA provider and embedded ActiveMQ for JMS. > > Running the project with camel:run results in three messages being sent > to > > the route. The first two are called explicitly in a userTransaction and > > behave as expected: the first is processed normally, the second triggers > a > > rollback (as expected). > > > > The third message is outside a userTransaction and throws the following > > exception from Atomikos: > > > > Caused by: com.atomikos.jms.AtomikosTransactionRequiredJMSException: > > The JMS session you are using requires a JTA transaction context for the > > calling thread and none was found. > > Please correct your code to do one of the following: > > 1. start a JTA transaction if you want your JMS operations to be > > subject to JTA commit/rollback, or > > 2. increase the maxPoolSize of the AtomikosConnectionFactoryBean to > > avoid transaction timeout while waiting for a connection, or > > 3. create a non-transacted session and do session acknowledgment > > yourself, or > > 4. set localTransactionMode to true so connection-level > commit/rollback > > are enabled. > > at > > com.atomikos.jms.AtomikosTransactionRequiredJMSException. > throwAtomikosTransactionRequiredJMSException( > AtomikosTransactionRequiredJMSException.java:23) > > ~[transactions-jms-4.0.4.jar:?] > > at > > com.atomikos.jms.ConsumerProducerSupport.enlist( > ConsumerProducerSupport.java:90) > > ~[transactions-jms-4.0.4.jar:?] > > at > > com.atomikos.jms.AtomikosJmsMessageProducerProxy.send( > AtomikosJmsMessageProducerProxy.java:34) > > ~[transactions-jms-4.0.4.jar:?] > > at > > org.springframework.jms.core.JmsTemplate.doSend(JmsTemplate.java:626) > > ~[spring-jms-4.3.11.RELEASE.jar:4.3.11.RELEASE] > > at > > org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.doSend( > JmsConfiguration.java:624) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate. > doSendToDestination(JmsConfiguration.java:563) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.component.jms.JmsConfiguration$ > CamelJmsTemplate.access$100(JmsConfiguration.java:505) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.component.jms.JmsConfiguration$ > CamelJmsTemplate$1.doInJms(JmsConfiguration.java:519) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:484) > > ~[spring-jms-4.3.11.RELEASE.jar:4.3.11.RELEASE] > > at > > org.apache.camel.component.jms.JmsConfiguration$CamelJmsTemplate.send( > JmsConfiguration.java:516) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.component.jms.JmsProducer.doSend(JmsProducer.java:440) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.component.jms.JmsProducer.processInOnly( > JmsProducer.java:394) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.component.jms.JmsProducer.process(JmsProducer.java:157) > > ~[camel-jms-2.20.0.jar:2.20.0] > > at > > org.apache.camel.processor.SharedCamelInternalProcessor.process( > SharedCamelInternalProcessor.java:186) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.processor.SharedCamelInternalProcessor.process( > SharedCamelInternalProcessor.java:86) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.impl.ProducerCache$1.doInProducer( > ProducerCache.java:541) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.impl.ProducerCache$1.doInProducer( > ProducerCache.java:506) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:369) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:506) > > ~[camel-core-2.20.0.jar:2.20.0] > > at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:229) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.impl.DefaultProducerTemplate.send( > DefaultProducerTemplate.java:144) > > ~[camel-core-2.20.0.jar:2.20.0] > > at > > org.apache.camel.impl.DefaultProducerTemplate.sendBody( > DefaultProducerTemplate.java:161) > > ~[camel-core-2.20.0.jar:2.20.0] > > ... 56 more > > > > > > I expected that "transacted()" on the route to have caused a transaction > to > > be created, and I am not sure why it has not been - other than it having > > something to do with this example running outside of a JEE Application > > Server. Is my expectation here incorrect? > > > > I believe the various required beans have been correctly configured as > > Producer methods under org.apache.camel.example.cdi.util.CdiProducers > > > > As an aside: in order to get this working in a Weld SE environment I use > a > > CDI extension > > (org.apache.camel.example.cdi.util.ResourceInjectReplacementExtension) > to > > add an @Inject annotation to the transactionManager attribute in > > org.apache.camel.cdi.transaction.JtaTransactionPolicy. Perhaps it > would be > > worth considering adding the annotation in camel-cdi to enable it to be > > used in a SE environment? (though I don't know if this would adversely > > affect the JEE world.) > > > > > > Any insights would be appreciated. > > > > Cheers, > > Gary > >