Skip to content

Commit fceb0ec

Browse files
garyrussellartembilan
authored andcommitted
GH-2532: Ignore Kotlin Continuation Parameter
Resolves #2532 The presence of the parameter caused the inferred type to be set to `null` due to ambiguous parameters present. It must be considered an ineligible type when inferring conversion types. **cherry-pick to 3.0.x (#2533), 2.4.x (#2534)** (cherry picked from commit f6d46f6)
1 parent 3980b32 commit fceb0ec

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ private boolean isEligibleParameter(MethodParameter methodParameter) {
425425
Type parameterType = methodParameter.getGenericParameterType();
426426
if (parameterType.equals(Channel.class)
427427
|| parameterType.equals(MessageProperties.class)
428-
|| parameterType.equals(org.springframework.amqp.core.Message.class)) {
428+
|| parameterType.equals(org.springframework.amqp.core.Message.class)
429+
|| parameterType.getTypeName().startsWith("kotlin.coroutines.Continuation")) {
429430
return false;
430431
}
431432
if (parameterType instanceof ParameterizedType) {

spring-rabbit/src/test/kotlin/org/springframework/amqp/rabbit/annotation/EnableRabbitKotlinTests.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import assertk.assertions.isEqualTo
2121
import assertk.assertions.isTrue
2222
import org.junit.jupiter.api.Test
2323
import org.springframework.amqp.core.AcknowledgeMode
24+
import org.springframework.amqp.core.MessageListener
2425
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory
2526
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory
2627
import org.springframework.amqp.rabbit.core.RabbitTemplate
2728
import org.springframework.amqp.rabbit.junit.RabbitAvailable
2829
import org.springframework.amqp.rabbit.junit.RabbitAvailableCondition
30+
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry
2931
import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler
32+
import org.springframework.amqp.utils.test.TestUtils
3033
import org.springframework.aop.framework.ProxyFactory
3134
import org.springframework.beans.BeansException
3235
import org.springframework.beans.factory.annotation.Autowired
@@ -57,17 +60,20 @@ class EnableRabbitKotlinTests {
5760
private lateinit var config: Config
5861

5962
@Test
60-
fun `send and wait for consume`() {
63+
fun `send and wait for consume`(@Autowired registry: RabbitListenerEndpointRegistry) {
6164
val template = RabbitTemplate(this.config.cf())
6265
template.convertAndSend("kotlinQueue", "test")
63-
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue();
66+
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue()
67+
val listener = registry.getListenerContainer("single").messageListener
68+
assertThat(TestUtils.getPropertyValue(listener, "messagingMessageConverter.inferredArgumentType").toString())
69+
.isEqualTo("class java.lang.String")
6470
}
6571

6672
@Test
6773
fun `send and wait for consume with EH`() {
6874
val template = RabbitTemplate(this.config.cf())
6975
template.convertAndSend("kotlinQueue1", "test")
70-
assertThat(this.config.ehLatch.await(10, TimeUnit.SECONDS)).isTrue();
76+
assertThat(this.config.ehLatch.await(10, TimeUnit.SECONDS)).isTrue()
7177
val reply = template.receiveAndConvert("kotlinReplyQueue", 10_000)
7278
assertThat(reply).isEqualTo("error processed");
7379
}
@@ -78,7 +84,7 @@ class EnableRabbitKotlinTests {
7884

7985
val latch = CountDownLatch(1)
8086

81-
@RabbitListener(queues = ["kotlinQueue"])
87+
@RabbitListener(id = "single", queues = ["kotlinQueue"])
8288
suspend fun handle(@Suppress("UNUSED_PARAMETER") data: String) {
8389
this.latch.countDown()
8490
}
@@ -121,7 +127,7 @@ class EnableRabbitKotlinTests {
121127

122128
}
123129

124-
@RabbitListener(queues = ["kotlinQueue1"], errorHandler = "#{eh}")
130+
@RabbitListener(id = "multi", queues = ["kotlinQueue1"], errorHandler = "#{eh}")
125131
@SendTo("kotlinReplyQueue")
126132
open class Multi {
127133

0 commit comments

Comments
 (0)