apache-camel - 用于从 ActiveMQ Artemis 传输消息或向 ActiveMQ Artemis 传输消息的 SJMS2 与 JMS 组件

标签 apache-camel jms activemq-artemis

我正在尝试找到使用 Camel 将消息从一个 ActiveMQ Artemis 队列传输到另一个队列的最快方法。我以为 Camel 的SJMS2组件将比 Camel 的传统组件更快 JMS组件,但使用 JMS 组件进行路由的速度快 2.5 倍(20,000 条消息/秒 vs 8,000 条消息/秒)。我使用 Camel 版本 2.20.2 和 Artemis 版本 2.11.0。

使用 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;
    }
}

使用SJMS2路由,其他设置如上面代码

@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");
        }
    };
}

如何使用 SJMS2 组件获得与 JMS 组件相同的速度?

最佳答案

克劳斯·易卜生在邮件列表中回复如下

200 consumers is too much. That instead makes it slower as you have 200 consumers racing for messages. Instead try to find a lower balance that is closer to cpu cores etc.

Also often a JMS client has a prefetch buffer (or some concept like this) which means a consumer may pre-download 1000 messages and then the other 199 consumers cant process these messages. So you need to tweak this option too.

Also if you have too many consumers and remote network connections then you get too chatty over IO etc. So its all about tuning depending on use-cases.

spring-jms has a thread pool built in that can automatic grow/shrink depending on load, and this can explain why its out of the box without tuning can appear to be faster.

Writing such logic is a bit more complex and this hasnt been added to sjms. I created a ticket about this https://issues.apache.org/jira/browse/CAMEL-14637

You can get in touch with commercial Camel supports as there are companies and consultants that has great experience with JMS brokers and Camel and to get them tuned to very high performance. The settings for JVM and OS and hardware can all make a big difference.

我还发现了一篇关于这个主题的好文章 https://dzone.com/articles/performance-tuning-ideas-for-apache-camel

关于apache-camel - 用于从 ActiveMQ Artemis 传输消息或向 ActiveMQ Artemis 传输消息的 SJMS2 与 JMS 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60414264/

相关文章:

java - 使用 Java 和 JMX/MBean 访问 Weblogic JMS

amazon-ec2 - 如何连接到 NAT 后面的 JMS 队列 JBoss EAP 7?

spring - 无法访问 Amazon SQS - InvalidClientTokenId

java - 无法使用 apache camel 3.4.3 和 Swagger 启动 Spring Boot 2.3.3

java - Apache Camel : Cached stream file deletion causing file not found errors

java - 具有多个消费者的 JMS 队列

jms - 为 Camel JMS 生产者设置 ConnectionFactory : camel-jms Vs camel-sjms

jms - 警告 : There are more than one servers on the network broadcasting the same node id

java - Artemis-2.6.3 控制台 : Service Unavailable

java - Camel servlet 没有带 http uri 的 spring 示例 <to> 标记?