0

我在 Jboss 7 应用程序中有一个 MDB,它充当 ActiveMQ 中队列的消费者。这就是从 JBoss 建立连接的方式

/subsystem=resource-adapters/resource-adapter=activemq-rar-5.6.0.rar/config-properties="ServerUrl":add(value="tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1")

在 MDB 上,这些是注释:

    @MessageDriven(name = "MyConsumerMessageBean", activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "myQueue"),
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),

    @ActivationConfigProperty(propertyName = "maxSessions", propertyValue="2")})
    @ResourceAdapter(value = "activemq-rar-5.6.0.rar")
    @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)

当 JBoss 连接到 Active MQ 时,我看到 jms.prefetchPolicy.queuePrefetch=1 的值在连接尝试中传递给了 activeMQ 服务器,如 JBoss 服务器日志中所示。

2014-08-28 21:33:04,183 INFO  [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-short-running-threads-threads - 3) Successfully established connection to broker [tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1]

但是,当我查看 ActiveMQ 队列屏幕并深入查看此使用者时,我看到 PreFetch Max Pending 列的值为 20。这个数字 20 来自哪里,为什么 ActiveMQ 不接受 1 的值。

我还尝试通过相同的机制设置其他值“jms.prefetchPolicy.all=1”,但这也不起作用。我在 JBoss AS 7.1.1 Final 和 ActiveMQ 5.6.0

谢谢

4

2 回答 2

1

首先确保您没有在消费者级别进行设置(例如 YOUR.QUEUE?consumer.prefetchSize=20)

这是唯一应该覆盖您在连接工厂中设置的位置的其他地方。

否则我也会考虑使用更新版本的 AMQ。如果我没记错的话,有一个错误导致代理不遵守预取值。

在您的 activemq.xml 中查看您是否有一个预取为 20 的目标策略,如果您没有在消费者级别找到它。在目标策略级别设置它会覆盖代理默认值 (1000),但 URI 参数应该覆盖该设置。这可能是您遇到我提到的问题的验证。

于 2014-08-29T19:31:22.670 回答
1

在 JBoss EAP 中,org.apache.activemq.ra.ActiveMQManagedConnectionFactory 被配置为不像往常那样从代理 url 获取参数。要配置预取,您可以将以下配置属性添加到资源适配器:

<config-property name="QueuePrefetch">20</config-property>
<config-property name="TopicPrefetch">20</config-property>
<config-property name="DurableTopicPrefetch">20</config-property>
<config-property name="OptimizeDurableTopicPrefetch">20</config-property>
<config-property name="QueueBrowserPrefetch">20</config-property>
<config-property name="InputStreamPrefetch">20</config-property> 
于 2016-10-20T19:20:19.533 回答