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**
This commit is contained in:
committed by
Artem Bilan
parent
77e1216559
commit
5f4c60a969
@@ -1197,8 +1197,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 && !isChannelTransacted()) {
|
||||
|
||||
@@ -241,7 +241,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"));
|
||||
assertThat(this.myService.channelBoundOk).isTrue();
|
||||
}
|
||||
|
||||
@@ -910,7 +910,7 @@ public class EnableRabbitIntegrationTests {
|
||||
this.txRabbitTemplate = txRabbitTemplate;
|
||||
}
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(
|
||||
@RabbitListener(id = "threadNamer", bindings = @QueueBinding(
|
||||
value = @Queue(value = "auto.declare", autoDelete = "true", admins = "rabbitAdmin"),
|
||||
exchange = @Exchange(value = "auto.exch", autoDelete = "true"),
|
||||
key = "auto.rk"), containerFactory = "txListenerContainerFactory"
|
||||
@@ -919,7 +919,7 @@ public class EnableRabbitIntegrationTests {
|
||||
this.channelBoundOk = this.txRabbitTemplate.execute(c -> {
|
||||
return c.equals(channel);
|
||||
});
|
||||
return foo.toUpperCase();
|
||||
return foo.toUpperCase() + Thread.currentThread().getName();
|
||||
}
|
||||
|
||||
@RabbitListener(queuesToDeclare = @Queue(name = "${jjjj:test.simple.declare}", durable = "true"),
|
||||
|
||||
Reference in New Issue
Block a user