【问题标题】:Configure ActiveMQ to add queue in-memory instead of disk配置 ActiveMQ 以在内存中而不是磁盘中添加队列
【发布时间】:2021-05-15 03:15:48
【问题描述】:

ActiveMQ 是否可以在内存中而不是磁盘中添加队列,如果可以,这样做的配置是什么。

这是我的activemq.xml,ActiveMQ版本是5.14.3。

我需要知道我应该在此处或任何其他配置文件中具体配置什么,以便队列在内存中而不是磁盘中。

我还需要将 ActiveMQ 开始的 Ram 增加到 2GB 的 Ram

<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}">

        <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

                    -->
                  <pendingMessageLimitStrategy>
                    <constantPendingMessageLimitStrategy limit="1000"/>
                  </pendingMessageLimitStrategy>
                </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>
                <memoryUsage>
                    <memoryUsage percentOfJvmHeap="70" />
                </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"/>
        </transportConnectors>

        <!-- 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>
<!-- END SNIPPET: example -->

【问题讨论】:

  • 下一次,我建议在您的问题中添加更多详细信息,例如您正在使用的 ActiveMQ 的确切版本,并可能告诉我们您尝试了什么以及结果。花一些时间阅读文档或在此论坛上搜索类似问题也会有所帮助。
  • 我已经做了 B. 在activemq.xml中禁用持久化(你还需要注释或者移除persistenceAdapter元素):
  • A 是不是强制的呢?

标签: linux activemq


【解决方案1】:

是的,它可以,并且有几种方法可以做到:

A.在 MessageProducer 或直接在发送操作上设置 NON_PERSISTENT 消息传递标志:

MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

B.在 activemq.xml 中禁用持久化(您还需要注释或删除 persistenceAdapter 元素):

<broker xmlns="http://activemq.apache.org/schema/core" persistent="false">
  <!--
  <persistenceAdapter>
    <kahaDB directory="${activemq.base}/data/kahadb"/>
  </persistenceAdapter>
  -->
</broker>

【讨论】:

  • 我已经做了 B. 在activemq.xml中禁用持久化(你还需要注释或者移除persistenceAdapter元素)
  • 那 A. 在 MessageProducer 上或直接在发送操作上设置 NON_PERSISTENT 消息传递标志是强制性的吗??
  • 我还需要增加activemq的内存大小我该怎么办
  • 一旦你使用了B,就不需要再使用A了。所有发送到这个broker的消息都不会持久化。对于其他问题,您需要设置memoryUsage limit
  • 对于配置中的内存限制,我有 所以我必须替换它还是离开并添加
猜你喜欢
  • 2016-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-24
  • 2015-08-06
  • 2015-06-27
  • 2019-06-02
  • 1970-01-01
相关资源
最近更新 更多