activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Böckling <mich...@boeckling.net>
Subject ActiveMQ, Weblogic and XA transactions in Spring
Date Fri, 28 Aug 2015 11:59:38 GMT
Hi!

I have a Spring app, and I'm trying to do XA transactions in Weblogic, using
a JDBC DataSource provided via Weblogic JNDI and an external ActiveMQ
instance, whose XAConnectionFactory is also provided via Weblogic JNDI.

I have not managed to make it work - is this possible at all? Do I need to
use the RAR? I tried, but got the following error which I have been unable
to fix:


Caused by: java.lang.Throwable: Substituted for missing class [1] More than
one Admin Objects implement interface "javax.jms.ConnectionFactory"
<admin-object-class> must be specified in admin-object-group in
weblogic-ra.xml. -
[2] More than one Admin Objects implement interface
"javax.jms.ConnectionFactory" <admin-object-class> must be specified in
admin-object-group in weblogic-ra.xml.


Here are some more details about my code, using the JNDI ConnectionFactory
approach:

I have added a foreign JMS server in Weblogic like this:

JNDI Initial Context Factory:

org.apache.activemq.jndi.ActiveMQInitialContextFactory
JNDI Connection URL:

tcp://localhost:61616
JNDI Properties:

connectionFactoryNames=XAConnectionFactory

To that server definition, I have added a ConnectionFactory (Remote JNDI
Name = XAConnectionFactory). Lookups work, so far so good.

In my code, this is how I setup the Spring JTA:

@Override
   @Bean
   @Profile(AppConfig.PROFILE_WEBLOGIC)
   public JtaTransactionManager transactionManager()
   {
      WebLogicJtaTransactionManager tx = new
WebLogicJtaTransactionManager();
      tx.afterPropertiesSet();

      return tx;
   }


And this is my JMS config:

@Bean
   @Profile(AppConfig.PROFILE_WEBLOGIC)
   public ConnectionFactory connectionFactory()
   {
      Properties props = new Properties();
      props.put(Context.INITIAL_CONTEXT_FACTORY,
env.getProperty(Context.INITIAL_CONTEXT_FACTORY));
      props.setProperty(Context.PROVIDER_URL,
env.getProperty(Context.PROVIDER_URL));

      try
      {
         InitialContext ctx = new InitialContext(props);
         ActiveMQXAConnectionFactory connectionFactory =
(ActiveMQXAConnectionFactory) ctx
            .lookup(env.getProperty("jms.connectionFactory"));

         return connectionFactory;
      }
      catch(NamingException e)
      {
         throw new RuntimeException("XAConnectionFactory lookup failed", e);
      }
   }

   @Bean
   public DefaultJmsListenerContainerFactory jmsListenerContainerFactory()
throws JMSException
   {
      DefaultJmsListenerContainerFactory factory = new
DefaultJmsListenerContainerFactory();
      factory.setConnectionFactory(connectionFactory());
      factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
      factory.setTransactionManager(txConfig.transactionManager());
      factory.setBackOff(new FixedBackOff());

      return factory;
   }

   @Bean(name = "jmsTemplate")
   @Override
   public JmsTemplate jmsTemplate() throws JMSException
   {
      JmsTemplate t = new JmsTemplate();
      t.setConnectionFactory(connectionFactory());
      t.setMessageTimestampEnabled(true);
      t.setMessageIdEnabled(true);

      return t;
   }


My JMS consumer is annotated with:

@Transactional   
@JmsListener(destination = "test.q1")

Is there anything I am missing?

Best regards,
Michael



--
View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-Weblogic-and-XA-transactions-in-Spring-tp4701487.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message