GH-905: Fix @RabbitListener Thread Names

Fixes https://github.com/spring-projects/spring-amqp/issues/905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**

(cherry picked from commit 5f4c60a969)

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java
This commit is contained in:
Gary Russell
2019-02-15 17:41:17 -05:00
committed by Artem Bilan
parent 2e962225c2
commit 88ee0f4457
2 changed files with 5 additions and 5 deletions

View File

@@ -1087,8 +1087,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
if (!this.isExposeListenerChannel() && this.transactionManager != null) {
logger.warn("exposeListenerChannel=false is ignored when using a TransactionManager");
}
if (!this.taskExecutorSet && StringUtils.hasText(this.getBeanName())) {
this.taskExecutor = new SimpleAsyncTaskExecutor(this.getBeanName() + "-");
if (!this.taskExecutorSet && StringUtils.hasText(getListenerId())) {
this.taskExecutor = new SimpleAsyncTaskExecutor(getListenerId() + "-");
this.taskExecutorSet = true;
}
if (this.transactionManager != null) {

View File

@@ -222,7 +222,7 @@ public class EnableRabbitIntegrationTests {
@Test
public void autoDeclare() {
assertEquals("FOO", rabbitTemplate.convertSendAndReceive("auto.exch", "auto.rk", "foo"));
assertEquals("FOOthreadNamer-1", rabbitTemplate.convertSendAndReceive("auto.exch", "auto.rk", "foo"));
}
@Test
@@ -757,13 +757,13 @@ public class EnableRabbitIntegrationTests {
public static class MyService {
@RabbitListener(bindings = @QueueBinding(
@RabbitListener(id = "threadNamer", bindings = @QueueBinding(
value = @Queue(value = "auto.declare", autoDelete = "true"),
exchange = @Exchange(value = "auto.exch", autoDelete = "true"),
key = "auto.rk")
)
public String handleWithDeclare(String foo) {
return foo.toUpperCase();
return foo.toUpperCase() + Thread.currentThread().getName();
}
@RabbitListener(queuesToDeclare = @Queue(name = "${jjjj:test.simple.declare}", durable = "true"))