【问题标题】:Maximum number of messages sent to a Queue in OpenMQ?OpenMQ中发送到队列的最大消息数?
【发布时间】:2010-12-16 16:33:22
【问题描述】:

我目前正在使用 Glassfish v2.1,并且我已经设置了一个队列来分别使用会话 bean 和 MDB 发送和接收消息。但是,我注意到我最多只能向队列发送 1000 条消息。为什么我不能向队列发送超过 1000 条消息?我确实为 glassfish 域设置了“开发人员”配置文件。这可能是原因吗?还是我需要修改一些资源配置设置?

我已将 sun-resources.xml 配置属性设置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
  <admin-object-resource
        enabled="true"
        jndi-name="jms/UpdateQueue"
        object-type="user"
        res-adapter="jmsra"
        res-type="javax.jms.Queue">
    <description/>
    <property name="Name" value="UpdatePhysicalQueue"/>
  </admin-object-resource>
  <connector-resource
        enabled="true" jndi-name="jms/UpdateQueueFactory"
        object-type="user"
        pool-name="jms/UpdateQueueFactoryPool">
    <description/>
  </connector-resource>
  <connector-connection-pool
        associate-with-thread="false"
        connection-creation-retry-attempts="0"
        connection-creation-retry-interval-in-seconds="10"
        connection-definition-name="javax.jms.QueueConnectionFactory"
        connection-leak-reclaim="false"
        connection-leak-timeout-in-seconds="0"
        fail-all-connections="false"
        idle-timeout-in-seconds="300"
        is-connection-validation-required="false"
        lazy-connection-association="false"
        lazy-connection-enlistment="false"
        match-connections="true"
        max-connection-usage-count="0"
        max-pool-size="32"
        max-wait-time-in-millis="60000"
        name="jms/UpdateFactoryPool"
        pool-resize-quantity="2"
        resource-adapter-name="jmsra"
        steady-pool-size="8"
        validate-atmost-once-period-in-seconds="0"/>
</resources>

嗯 .. 进一步调查在 imq 日志中发现以下内容:

   [17/Nov/2009:10:27:57 CST] ERROR sendMessage: Sending message failed. Connection ID: 427038234214377984:
    com.sun.messaging.jmq.jmsserver.util.BrokerException: transaction failed: [B4303]: The maximum number of messages [1,000] that the producer can process in a single transaction (TID=427038234364096768) has been exceeded. Please either limit the # of messages per transaction or increase the imq.transaction.producer.maxNumMsgs property.

如果我需要一次发送超过 5000 条消息,我该怎么办?

我要做的是读取表中的所有记录,并根据我只有只读访问权限的旧表中该记录的相应值更新每条记录的特定字段。该表中有超过 10k 条记录。到目前为止,我在for循环中依次遍历每条记录,从遗留表中获取相应的记录,比较字段值,必要时更新记录并在其他表中添加相应的新记录。

但是,我希望通过异步处理所有记录来提高性能。为此,我考虑将每个记录信息作为单独的消息发送,因此需要这么多消息。

【问题讨论】:

    标签: glassfish queue jms ejb jboss-mdb


    【解决方案1】:

    要配置 OpenMQ 并设置代理代理属性,请查看此blog post。

    但实际上,我不建议增加imq.transaction.producer.maxNumMsgs 属性,至少不要超过documentation 中推荐的值:

    生产者在单个事务中可以处理的最大消息数。建议该值小于 5000,以防止资源耗尽。

    如果您需要发送更多消息,请考虑在多个事务中进行。

    【讨论】:

    • 我围绕 JMS 连接编写了一个简单的包装器来提交消息是块。 gist.github.com/837393
    • @OleTraveler 我查看了您的代码。它真的这样工作吗?关闭和重新打开 JMS 连接不会启动新事务。因此,您的代码不应与容器管理的事务一起使用。
    • 我发布了一个相关问题,您最终可以回答:stackoverflow.com/questions/6233854/…。这是关于如何将多个事务中的 JMS 消息与容器管理的事务分开发送。
    • 在我使用 XA 事务之前,该代码对我有用。我认为基本上没有 XA 事务,您可以在 Session bean 中执行多个事务(有点像 Bean 管理的持久性。但它不适用于 XA 事务。我想也许如果我使用 bean 管理的持久性并提交 Session Bean 的事务以及它可能工作的 JMX 事务。
    猜你喜欢
    • 2018-09-26
    • 2013-07-13
    • 2016-05-02
    • 2012-02-12
    • 1970-01-01
    • 2015-03-21
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多