首页 > 解决方案 > 使用 JMS 线程池的协程重复线程

问题描述

我有一些逻辑,它使用 JMS 队列线程池。它一般看起来如何:

[request thread] -> jms -> JMS listener [thread pool] -> reactive web client

现在我收到重复的消息(例如 - 错误)

ERROR [DefaultMessageListenerContainer-5 @coroutine#2]
ERROR [DefaultMessageListenerContainer-4 @coroutine#4]
ERROR [DefaultMessageListenerContainer-1 @coroutine#1]
ERROR [DefaultMessageListenerContainer-3 @coroutine#3]

此类协程由runBlocking.

@JmsListener(destination = ...)
fun someHandleFunction(...) = runBlocking {
   someWebClientService.createRequest(...)
}

// SomeWebClientService class
suspend fun createRequest(...) = try {
   val response = webClient
       .post()
       .uri { ... }
       ...
       .exchange()
       .awaitFirst()

   // Check response status here
} catch (e: Exception) { 
   // Some error handling here
}

是的,我知道在runBlockin协程的情况下可以以这种方式运行......但是为什么协程线程与新线程相关联?

这种重复有什么问题?

标签: kotlinreactive-programmingkotlin-coroutines

解决方案


问题与 JMS 配置有关。

出于某种原因,如果没有此配置,单独的 JMS 线程只能处理一个任务

spring:
     artemis.embedded:
           persistent: true
           data-directory: ./target/some-queue-storage
           queues: ...

推荐阅读