【问题标题】:Improving JMS message consumption speed of application提高应用的JMS消息消费速度
【发布时间】:2017-05-04 12:34:27
【问题描述】:

我们有一个应用程序,它每分钟可以消耗大约 300 条 JMS 消息。我们需要将速度提高到每分钟 3000 条消息。

我创建了一个简单的测试程序,它从队列中读取消息并记录消息。不涉及处理,所以我期望高速。但是,日志记录仍以每分钟约 400 条消息的速度发生。

以下是我的节目节选

<int-jms:message-driven-channel-adapter id="testJmsInboundAdapter" 
    auto-startup="true"
    destination="testQueueDestination" 
    connection-factory="testConnectionFactory" 
    channel="messageTransformerChannel" />

<int:channel id="messageTransformerChannel" />

<int:service-activator 
    id="loggerActivator"
    input-channel="messageTransformerChannel" 
    method="log"
    ref="logger" />

logger 方法只是简单地记录消息

public void log(final GenericMessage<Object> object) {
        LOGGER.info("Logging message" + object);
    }

任何建议我应该在哪里查看瓶颈。使用spring integration的message-driven-channel-adapter每分钟可以消费的消息数量有没有限制

【问题讨论】:

    标签: spring-integration spring-jms


    【解决方案1】:

    注意这些选项:

    <xsd:attribute name="concurrent-consumers" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation>
                    Specify the number of concurrent consumers to create. Default is 1.
                        Specifying a higher value for this setting will increase the standard
                        level of scheduled concurrent consumers at runtime: This is effectively
                        the minimum number of concurrent consumers which will be scheduled
                        at any given time. This is a static setting; for dynamic scaling,
                        consider specifying the "maxConcurrentConsumers" setting instead.
                        Raising the number of concurrent consumers is recommendable in order
                        to scale the consumption of messages coming in from a queue. However,
                        note that any ordering guarantees are lost once multiple consumers are
                        registered
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="max-concurrent-consumers" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation>
                     Specify the maximum number of concurrent consumers to create. Default is 1.
                         If this setting is higher than "concurrentConsumers", the listener container
                         will dynamically schedule new consumers at runtime, provided that enough
                         incoming messages are encountered. Once the load goes down again, the number of
                         consumers will be reduced to the standard level ("concurrentConsumers") again.
                         Raising the number of concurrent consumers is recommendable in order
                        to scale the consumption of messages coming in from a queue. However,
                        note that any ordering guarantees are lost once multiple consumers are
                        registered.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
    

    【讨论】:

    • 谢谢,使用 concurrent-consumer="5" 将处理速度提高到每分钟 2k 条消息
    • 你能解释一下并发消费者属性是如何工作的吗?如果我将 concurrent-consumer 值设置为 5,它是否会创建 5 个线程同时开始从 JMS 队列中读取。此外,如果最终使用上例中检索到的消息的 logger bean 是作用域原型 - 是否会为每个线程创建不同的 logger bean 或所有线程都引用同一个 logger bean
    • 是的,他们会同时这样做。 Logger bean 只会为 Service Activator 端点创建一次,并且仅在应用程序启动应用程序期间创建。一切安好,请阅读DefaultMessageListenerContainer.setConcurrency(String concurrency) JavaDocs。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2016-06-14
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多