如何正确配置ActiveMQ与池?

Diy*_*yko 10 activemq-classic connection-pooling apache-camel

我们对AMQ使用以下配置

<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${brokerURL1}"/>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
    <property name="maxConnections" value="10"/>
    <property name="maximumActive" value="100"/>
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
</bean>
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="transacted" value="false"/>
    <property name="concurrentConsumers" value="5"/>
    <property name="maxConcurrentConsumers" value="10"/>
</bean>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

我经常有一个奇怪的问题 - 松散的信息.实际上AMQ表示一切正常并且消息已经出列但是应用程序上没有消息...

我已经读过它可能是缓存消费者的问题,而应该在配置后使用JmsConfiguration

<bean id="jmsConfig" class="org.apache.activemq.camel.component.ActiveMQConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="transacted" value="false"/>
    <property name="concurrentConsumers" value="5"/>
    <property name="maxConcurrentConsumers" value="10"/>
    <property name="cacheLevelName" value="CACHE_CONSUMER"/>
</bean>
Run Code Online (Sandbox Code Playgroud)

有谁知道如何正确配置activemq?哪些值应设置为最佳性能和良好的可靠性?

<property name="maxConnections" value="?"/>
<property name="maximumActive" value="?"/>
<property name="concurrentConsumers" value="?"/>
<property name="maxConcurrentConsumers" value="?"/>
Run Code Online (Sandbox Code Playgroud)

我应该使用org.apache.activemq.pool.PooledConnectionFactory还是有更好的方法?

Pet*_*der 6

看起来你更想问如何配置Apache Camel如何使用ActiveMQ.

根据您在设置中看到的使用/负载模式以及您的要求,有很多方法可以严格配置池等.您引用maxConcurrentConsumers等的那些设置将取决于您的Camel路由以及您在那里设置的消费者数量.

简单地说,有两种方案可以优化:发送和接收消息(请求/回复也会浮现在脑海中,但这是另一回事).

如果您在应用程序中收到大量消息,那么您通常会设置消息监听器并且池化并没有太大帮助,因为您不会创建/拆除大量连接/会话.只需确保配置足够的并发使用者 - 多少取决于您的硬件(#CPU核心等)和每条消息的大小.您必须测量特定设置以获得最佳性能.

当您发送消息时,Camel会建议您使用ActiveMQ 的PooledConnectionFactory.链接到的文档还会为您要求的设置建议一些默认值.

  <property name="maxConnections" value="8" />
  <property name="maximumActive" value="500" />
   <property name="transacted" value="false"/>
Run Code Online (Sandbox Code Playgroud)

为了获得最大的可靠性,您应该使用事务处理会话,并在安全处理后提交收到的消息.

奇怪的是,你说你丢失了消息,你的设置中没有任何特定的东西可以让你丢失消息.您需要进一步跟踪这一点,或者提供有关应用程序实现的一些信息.