// shall I write some keywords here to boost search engine ranking?

Sunday, September 21, 2008

ActiveMQ Failover with Async Send

Apche ActiveMQ is a popular open source JMS Message Broker. As in version 5.0, it support failover transport, and async send. But not both at the same time.

Both connection string below will NOT work:

failover:(tcp://remotehost:61616,tcp://localhost:61616)?jms.useAsyncSend=true
failover:(tcp://remotehost:61616?jms.useAsyncSend=true,tcp://localhost:61616?jms.useAsyncSend=true)

So the dirty trick I use is to write my own ContextFactory that override 'org.apache.activemq.jndi.ActiveMQInitialContextFactory'


package org.apache.activemq.jndi;

import java.net.URISyntaxException;
import java.util.Hashtable;

import org.apache.activemq.ActiveMQConnectionFactory;

public class ActiveMQOptimisedSendInitialContextFactory extends ActiveMQInitialContextFactory{

@Override
protected ActiveMQConnectionFactory createConnectionFactory(
Hashtable environment
) throws URISyntaxException {
ActiveMQConnectionFactory connFactory = super.createConnectionFactory(environment);

connFactory.setUseAsyncSend(true);

return connFactory;

}

@Override
protected ActiveMQConnectionFactory createConnectionFactory(
String name,
Hashtable environment
) throws URISyntaxException {
ActiveMQConnectionFactory connFactory = super.createConnectionFactory(name, environment);

connFactory.setUseAsyncSend(true);

return connFactory;
}

}


Using this class as JNDI's 'java.naming.factory.initial', then the connection will be using async send by default, inlude failover transport.

1 comment:

Anonymous said...

Hello. And Bye.