8 Replies Latest reply: Dec 15, 2009 6:17 AM by Alphonse Bendt RSS

Embedding HornetQ and a Bridge

Alphonse Bendt Newbie

Hi,

i'm trying to embed HornetQ and a Hornet Bridge into an application. The plan is to let the application put its messages into the embedded queue and enable a Bridge whenever the Network is available. Then the Bridge should push all Messages into another (remote) queue.

So far I've followed the embedding examples. This worked fine for the embedded queue part. Right now I'm struggling to set up the Bridge.

The Bridge tries to locate a Transaction Manager. Can I use the Bridge without one?

Here's my setup code so far:

bridge = new JMSBridgeImpl();

 Properties props = new Properties();
 InputStream in = getClass().getResourceAsStream("/jndi.properties");

 props.load(in);

 in.close();

 ic = new InitialContext(props);

 bridge.setSourceConnectionFactoryFactory(new ConnectionFactoryFactory() {
 public ConnectionFactory createConnectionFactory() throws Exception {
 return hornetServer.getConnectionFactory();
 }
 });

 bridge.setSourceDestinationFactory(new DestinationFactory() {
 public Destination createDestination() throws Exception {
 return new HornetQQueue("embeddedQueue");
 }
 });

 bridge.setTargetConnectionFactoryFactory(new ConnectionFactoryFactory() {
 public ConnectionFactory createConnectionFactory() throws Exception {
 return (ConnectionFactory) ic.lookup("ConnectionFactory");
 }
 });

 bridge.setTargetDestinationFactory(new DestinationFactory() {
 public Destination createDestination() throws Exception {
 return (Queue)ic.lookup("remoteQueue");
 }
 });

 bridge.setFailureRetryInterval(5000L);

 bridge.setMaxRetries(-1);

 bridge.setMaxBatchSize(10);

 bridge.setMaxBatchTime(1000);

 bridge.setQualityOfServiceMode(QualityOfServiceMode.DUPLICATES_OK);

 bridge.start();


bridge.start() throws the following exception:
java.lang.RuntimeException: Unable to locate the transaction manager
 at org.jboss.tm.TransactionManagerLocator.locate(TransactionManagerLocator.java:134)
 at org.jboss.tm.TransactionManagerLocator.locate(TransactionManagerLocator.java:113)
 at org.hornetq.jms.bridge.impl.JMSBridgeImpl.getTm(JMSBridgeImpl.java:747)
 at org.hornetq.jms.bridge.impl.JMSBridgeImpl.start(JMSBridgeImpl.java:231)
 at com.kiongroup.tdm.fe.messaging.impl.JMSBridge.start(JMSBridge.java:81)


Using HornetQ 2.0.0.Beta5 and trying to connect to a JBoss EAP 5.0.0

How do I need to setup the bridge. Does anyone has a working example?

thanks in advance,
Alphonse Bendt

  • 1. Re: Embedding HornetQ and a Bridge
    Tim Fox Master

    Try the latest version CR1.

    Beta5 is older.

  • 2. Re: Embedding HornetQ and a Bridge
    Alphonse Bendt Newbie

    will do. it would be great if the CR1 was available in the jboss maven repo too.

  • 3. Re: Embedding HornetQ and a Bridge
    Tim Fox Master

    BTW we will probably have CR2 out on Monday

  • 4. Re: Embedding HornetQ and a Bridge
    Alphonse Bendt Newbie

    I tried out 2.0.0.CR1.

     

    this gives me an exception too:

     

    java.lang.IllegalStateException: unable to create TransactionManager from org.hornetq.integration.jboss.tm.JBoss5TransactionManagerLocator.getTm
         at org.hornetq.jms.bridge.impl.JMSBridgeImpl.getTm(JMSBridgeImpl.java:870)
         at org.hornetq.jms.bridge.impl.JMSBridgeImpl.start(JMSBridgeImpl.java:286)
         at com.kiongroup.tdm.fe.messaging.impl.JMSBridge.start(JMSBridge.java:114)
    ...
    Caused by: java.lang.ClassNotFoundException: org.hornetq.integration.jboss.tm.JBoss5TransactionManagerLocator
         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
         at org.hornetq.jms.bridge.impl.JMSBridgeImpl.getTm(JMSBridgeImpl.java:863)
    

     

    Seems like the Bridge is still depending on a Transaction Manager. Is it supported to run the Bridge without it?

    I tried to configure the bridge to use a no op Transaction Manager:

     

        TransactionManager transactionManager = new TransactionManager() {
            public void begin() throws NotSupportedException, SystemException {
            }
    
            ... // empty implementation of the javax.transaction.TransactionManager interface .
    
            public void resume(Transaction transaction) throws InvalidTransactionException, IllegalStateException, SystemException {
            }
        };
    
        bridge.setTransactionManager(transactionManager);
    
        bridge.start();
    

     

    this way i'm able to start the bridge. is this a recommended approach?

     

    thanks,

         Alphonse

  • 5. Re: Embedding HornetQ and a Bridge
    Jeff Mesnil Master

    A TransactionManager is required by HornetQ JMS Bridge.

     

    Did you look at the example jms/jms-bridge which lists the 4 jars you need to use JBoss Transactions?

  • 6. Re: Embedding HornetQ and a Bridge
    Alphonse Bendt Newbie

    ok thanks.

     

    now i'm also creating a transaction manager (pojo com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple like in the jms/jms-bridge demo).

     

    i configure the bridge to use this transaction manager.

     

    javax.transaction.TransactionManager transactionManager =
       new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple();
    
    ...
    
    bridge.setTransactionManager(transactionManager);
    
    bridge.start();
    

     

    after that the bridge started and the messages from the embedded queue are transfered to the server queue.

     

    thanks for giving the hints.

     

    Alphonse

  • 7. Re: Embedding HornetQ and a Bridge
    Tim Fox Master

    Ah, you meant a *JMS* bridge.

     

    Yes, that will require a transaction manager.

     

    Although we don't recommend a JMS bridge if you're just connecting two HornetQ instances, in that cse you should use a core bridge, which doesn't require a transaction manager.

     

    See user manual for more info.

  • 8. Re: Embedding HornetQ and a Bridge
    Alphonse Bendt Newbie

    i was aware of your recommendation to use the core bridge to connect two HornetQ instances.

    however my remote queue is provided by a jboss eap server which is using the  old jboss messaging.