首页 > 解决方案 > 消息处理在 Spring 集成中随机暂停/暂停一小段时间

问题描述

我有一个使用 spring 集成框架进行消息处理的应用程序(网关 -> 转换 -> 服务激活器)。我面临的问题之一是处理消息有相当长的延迟,从几毫秒到几秒不等。滞后并不一致,似乎消息被搁置并一次处理。

我尝试使用 YourKit 分析应用程序,但找不到任何死锁或阻塞的线程。打开 org.springframework.integration 的调试日志也没有提供太多信息。这是spring集成xml:

    <int:gateway service-interface="com.test.MessageGateway"
            id="msggateway" default-request-channel="msginputchannel" />

    <int:channel id="msginputchannel">
            <int:queue capacity="5000" />
    </int:channel>

    <int:bridge id="msginputbridge" input-channel="msginputchannel" output-channel="msgchannel">
            <int:poller fixed-delay="100"/>
    </int:bridge>

    <int:channel id="msgchannel">
            <int:queue capacity="5000" />
    </int:channel>

    <int:transformer input-channel="msgchannel"
            output-channel="msgPubSubchannel" id="msgtransformer" ref="msgserializer" method="serialzeTo" >
            <int:poller fixed-delay="100"  />
    </int:transformer>

    <int:publish-subscribe-channel id="msgPubSubchannel" />

    <int:bridge id="msgQueueSystembridge" input-channel="msgPubSubchannel" output-channel="msgQueueSystemqueuechannel"/>
    <int:channel id="msgQueueSystemqueuechannel">
            <int:queue capacity="5000"/>
    </int:channel>

    <int:service-activator id="msgQueueSystempublisher" ref="msgQueueSystemadapter" input-channel="msgQueueSystemqueuechannel" method="publish" >
            <int:poller fixed-delay="100"/>
    </int:service-activator>

    <int:bridge id="msgbridge" input-channel="msgPubSubchannel" output-channel="msgFileSystemchannel"/>
    <int:channel id="msgFileSystemchannel">
            <int:queue capacity="5000"/>
    </int:channel>

    <int:service-activator id="msgfilewriter" ref="msgadapter" input-channel="msgFileSystemchannel" method="publish" >
            <int:poller fixed-delay="100"/>
    </int:service-activator>

关于如何进行调试的任何指示?

标签: springspring-integration

解决方案


您使用了很多QueueChannels 并且它们的所有轮询任务都基于TaskSheduler线程池的默认设置10。所以,对于你来说,所有任务只共享这 10 个线程确实可能是一个瓶颈。

您可能会考虑不要在两者之间使用太多队列:我看不出有理由在流程中的所有步骤上排队。

另一方面,您可以使用集成spring.integration.taskScheduler.poolSize属性将该池大小增加到所需的数量:https ://docs.spring.io/spring-integration/docs/current/reference/html/whats-new.html#x51.-全局属性


推荐阅读