I am trying to find the fastest way using Camel to transfer messages from one ActiveMQ Artemis queue to another. I thought that Camel's SJMS2 component would be faster than Camel's traditional JMS component, but routing with the JMS component is 2.5 times faster (20,000 vs 8,000 msg/s). I use Camel version 2.20.2 and Artemis version 2.11.0.
Route with JMS
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
import javax.jms.ConnectionFactory;
import java.util.concurrent.TimeUnit;
public class JMSTransferTest extends CamelTestSupport {
@Test
public void testArtemis() throws Exception {
TimeUnit.SECONDS.sleep(100);
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
from("jms://TEST.IN?connectionFactory=#artemisCF&concurrentConsumers=200")
.to("jms://TEST.OUT?connectionFactory=#artemisCF");
}
};
}
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
final ConnectionFactory connFactory = new ActiveMQConnectionFactory("tcp://localhost:61622");
final ConnectionFactory connFactoryDeadLeatter = new ActiveMQConnectionFactory("tcp://localhost:61622");
JmsPoolConnectionFactory pooledConnectionFactory = new JmsPoolConnectionFactory();
pooledConnectionFactory.setConnectionFactory(connFactory);
pooledConnectionFactory.setMaxConnections(20);
pooledConnectionFactory.setMaxSessionsPerConnection(100);
registry.bind("artemisCF", pooledConnectionFactory);
registry.bind("deadLetterCF", connFactoryDeadLeatter);
return registry;
}
}
Route with SJMS2, other settings as in the code above
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
from("sjms2://TEST.IN?connectionFactory=#artemisCF&consumerCount=200&asyncStartListener=true")
.to("sjms2://TEST.OUT?connectionFactory=#artemisCF");
}
};
}
How can I use the SJMS2 component to get the same speeds as JMS component?