队列消耗缓慢

时间:2019-05-18 19:43:38

标签: apache-camel activemq

我使用带有activemqsslconnectionfactory的骆驼来处理我的cxf消息。我的写入队列速率几乎为30 req / s。但是读起来很慢,因此我的队列从来都不为空。

我也使用了慢速消费者策略,但没有什么不同(我不确定我是否设置为true),并且我增加了并发的消费者以及masActivesessionpercon和maxconnection,但这并没有太大不同,我们也使用了poolconnectionfactory。

这是服务器activemq.xml:

<beans
  xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <!-- Allows us to use system properties as variables in this configuration file -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <value>file:${activemq.conf}/credentials.properties</value>
        </property>
    </bean>

   <!-- Allows accessing the server log -->
    <bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
          lazy-init="false" scope="singleton"
          init-method="start" destroy-method="stop">
    </bean>

    <!--
        The <broker> element is used to configure the ActiveMQ broker.
    -->
    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}"  persistent="false">

        <destinationPolicy>
            <policyMap>
              <policyEntries>
                <policyEntry topic=">" >
                    <!-- The constantPendingMessageLimitStrategy is used to prevent
                         slow topic consumers to block producers and affect other consumers
                         by limiting the number of messages that are retained
                         For more information, see:

                         http://activemq.apache.org/slow-consumer-handling.html
                  -->
                <deadLetterStrategy>
                    <sharedDeadLetterStrategy processExpired="false" />
                </deadLetterStrategy>
                </policyEntry>

        <policyEntry queue=">" >
                <messageEvictionStrategy>
<!--                     <oldestMessageEvictionStrategy/>-->
<oldestMessageWithLowestPriorityEvictionStrategy/>
                </messageEvictionStrategy>
        </policyEntry>

        <policyEntry queue=">">
        <!-- Force pending messages to be discarded for slow consumers -->
             <pendingMessageLimitStrategy>
               <constantPendingMessageLimitStrategy limit="5"/>
             </pendingMessageLimitStrategy>
              <!-- 10 seconds worth -->
             <subscriptionRecoveryPolicy>
                <timedSubscriptionRecoveryPolicy recoverDuration="10000"/>
             </subscriptionRecoveryPolicy>
     <!--<messageEvictionStrategy>
                <oldestMessageWithLowestPriorityEvictionStrategy/>
             <messageEvictionStrategy/>-->
           </policyEntry>
        <policyEntry topic=">" >
                <messageEvictionStrategy>
<!--                     <oldestMessageEvictionStrategy/>-->
<oldestMessageWithLowestPriorityEvictionStrategy/>
                </messageEvictionStrategy>
        </policyEntry>

         <policyEntry topic=">">
        <!-- Force pending messages to be discarded for slow consumers -->
             <pendingMessageLimitStrategy>
               <constantPendingMessageLimitStrategy limit="5"/>
             </pendingMessageLimitStrategy>
              <!-- 10 seconds worth -->
             <subscriptionRecoveryPolicy>
                <timedSubscriptionRecoveryPolicy recoverDuration="10000"/>
             </subscriptionRecoveryPolicy>
     <!--<messageEvictionStrategy>
                <oldestMessageWithLowestPriorityEvictionStrategy/>
             <messageEvictionStrategy/>-->
           </policyEntry>
              </policyEntries>
            </policyMap>
        </destinationPolicy>

        <!--
            The managementContext is used to configure how ActiveMQ is exposed in
            JMX. By default, ActiveMQ uses the MBean server that is started by
            the JVM. For more information, see:

            http://activemq.apache.org/jmx.html
        -->
        <managementContext>
            <managementContext createConnector="false"/>
        </managementContext>

        <!--
            Configure message persistence for the broker. The default persistence
            mechanism is the KahaDB store (identified by the kahaDB tag).
            For more information, see:

            http://activemq.apache.org/persistence.html
        -->
        <persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>

          <!--
            The systemUsage controls the maximum amount of space the broker will
            use before disabling caching and/or slowing down producers. For more information, see:
            http://activemq.apache.org/producer-flow-control.html
          -->
          <systemUsage>
            <systemUsage  sendFailIfNoSpace="true">
                <memoryUsage >
                    <memoryUsage limit="1 gb" />
                </memoryUsage>
                <storeUsage>
                    <storeUsage limit="100 gb"/>
                </storeUsage>
                <tempUsage>
                    <tempUsage limit="50 gb"/>
                </tempUsage>
            </systemUsage>
        </systemUsage>

        <!--
            The transport connectors expose ActiveMQ over a given protocol to
            clients and other brokers. For more information, see:

            http://activemq.apache.org/configuring-transports.html
        -->
        <transportConnectors>
            <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
           <!-- <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>>
            <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
            <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>-->
              <transportConnector name="ssl" uri="ssl://0.0.0.0:8081?trace=true&amp;needClientAuth=true&amp;maximumConnections=10000&amp;wireFormat.maxFrameSize=104857600"/>
        </transportConnectors>
        <sslContext>
             <sslContext keyStore="/home/ut/keys/key.jks"
                         keyStorePassword="!QAZ2wsx"
                         trustStore="/home/ut/keys/trust.jks"
                         trustStorePassword="password" />
          </sslContext>
        <!-- destroy the spring context on shutdown to stop jetty -->
        <shutdownHooks>
            <bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
        </shutdownHooks>

    </broker>

    <!--
        Enable web consoles, REST and Ajax APIs and demos
        The web consoles requires by default login, you can disable this in the jetty.xml file

        Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
    -->
    <import resource="jetty.xml"/>

</beans>

这是骆驼面(几乎):

ActiveMQSslConnectionFactory activeMQConnectionFactory = new ActiveMQSslConnectionFactory();
String activeMQHost = activeMQConfig.getBrokerURL();
String activeMQIp = HostPropertiesManager.getInstance().getIP(activeMQHost);

if (activeMQIp.contains("127.0.0.1")) {
    activeMQConnectionFactory.setBrokerURL("tcp://" + activeMQIp + ":61617");
} else {
    activeMQConnectionFactory.setBrokerURL("ssl://" + activeMQIp + ":8081");
}

activeMQConnectionFactory.setTrustAllPackages(activeMQConfig.isTrustAllPackages());
activeMQConnectionFactory.setKeyStore("queueKeys/key.jks");
activeMQConnectionFactory.setKeyStorePassword(activeMQConfig.getKeyStorePassword());
activeMQConnectionFactory.setTrustStore("queueKeys/trust.jks");
activeMQConnectionFactory.setTrustStorePassword(activeMQConfig.getTrustStorePassword());
activeMQConnectionFactory.setDispatchAsync(true);
activeMQConnectionFactory.setAlwaysSyncSend(true);
activeMQConnectionFactory.setAlwaysSessionAsync(true);
activeMQConnectionFactory.setUseAsyncSend(true);

PooledConnectionFactory connectionFactory = new PooledConnectionFactory(activeMQConnectionFactory);
            connectionFactory.setMaxConnections(50000);
            connectionFactory.setMaximumActiveSessionPerConnection(3000000);
            JmsConfiguration configuration = new JmsConfiguration(connectionFactory);
            configuration.setTimeToLive(20000);
            configuration.setConcurrentConsumers(500);
            configuration.setLazyCreateTransactionManager(false);
            configuration.setReceiveTimeout(40000);
            configuration.setRequestTimeout(40000);
            configuration.setTransferException(true);
            configuration.setMaxConcurrentConsumers(600);
            configuration.setAcceptMessagesWhileStopping(true);
            ActiveMQComponent activeMQComponent = new ActiveMQComponent();
            activeMQComponent.setConfiguration(configuration);
            getContext().addComponent("activemq" + serviceName, activeMQComponent);

有希望吗?

0 个答案:

没有答案