【问题标题】:JmsOutboundGateway : Manual Start and StopJmsOutboundGateway : 手动启动和停止
【发布时间】:2016-12-15 19:28:30
【问题描述】:

我们有一个包含大约 75 个分区步骤的应用程序,分布在大约 100 个作业中。我们对出站网关的配置是:

<int-jms:outbound-gateway 
    id="outbound-gateway_1"
    auto-startup="true" 
    connection-factory="jmsConnectionFactory"
    request-channel="jms.requests_1"
    request-destination="jms.requestsQueue"
    reply-channel="jms.reply_1"
    reply-destination="jms.repliesQueue"
    receive-timeout="${timeout}"
    correlation-key="JMSCorrelationID" >
    <int-jms:reply-listener receive-timeout="1000"/>
</int-jms:outbound-gateway>

当 autostart="true" 时,我们会看到每个出站网关的 replyListener 线程。为了消除这种额外的负载和资源消耗,我们更改为 autostart="false" 并为分区步骤添加了一个步骤侦听器,即在 beforeStep 和 afterStep 方法中启动和停止网关。在服务器启动时,replyListener 线程并不像预期的那样存在。它们在步骤执行期间出现,但在出站网关上停止调用后不会被删除(即使在等待很长时间后)。

清理replyListener 是否需要其他东西?

【问题讨论】:

  • 你怎么知道那些线程还在?您使用哪个版本的 Spring Integration?谢谢

标签: spring-integration spring-batch spring-jms


【解决方案1】:

好的,我明白你的意思了。看起来像:

while ((active = isActive()) && !isRunning()) {
    if (interrupted) {
        throw new IllegalStateException("Thread was interrupted while waiting for " +
                "a restart of the listener container, but container is still stopped");
    }
    if (!wasWaiting) {
            decreaseActiveInvokerCount();
    }
    wasWaiting = true;
    try {
        lifecycleMonitor.wait();
    }
    catch (InterruptedException ex) {
        // Re-interrupt current thread, to allow other threads to react.
        Thread.currentThread().interrupt();
        interrupted = true;
    }
}

DefaultMessageListenerContainer.AsyncMessageListenerInvoker.executeOngoingLoop()

那里有lifecycleMonitor.wait();,关注IllegalStateException的留言。

不确定这种设计的目的是什么,但我们别无选择,除非按原样接受。

进一步start()中的逻辑基于this.pausedTasks本地缓存,如果容器!this.runningdoInitialize()期间填充。

如果您认为必须以某种方式更改逻辑,请随时提出JIRA

【讨论】:

  • 我们所有的分区分区作业都监听同一个 JMS 队列并使用不同的通道。有没有办法将出站网关配置为使用相同的 replyListener 实例,它们只需要运行 1 个(摆脱启动和停止?
  • 考虑不要将&lt;int-jms:reply-listener&gt; 用于您的用例。我什至不确定您的动态样本是否需要静态reply-destinationTemporaryQueue 解决方案就足够了。
  • 使用喜欢短期任务的外部任务执行器,或显式设置max-messages-per-task(该类型的执行器设置为10)。当每个任务的最大消息数大于 0 时,线程将终止(或放回池中)而不是在该监视器上阻塞。
猜你喜欢
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-19
  • 2016-12-19
  • 1970-01-01
  • 2023-02-02
  • 2020-08-09
相关资源
最近更新 更多