Skip to content

Commit

Permalink
GH-1433: Fix DMLC Monitor Thread Name
Browse files Browse the repository at this point in the history
Resolves #1433

Used `beanName` instead of `listenerId` (which falls back to `beanName` if `null`).
Containers for annotations are not beans per se.

**cherry-pick to 2.4.x, 2.3.x**
  • Loading branch information
garyrussell authored and artembilan committed Mar 15, 2022
1 parent d5e7c3f commit 0ccfcbe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute();

@Nullable
private String beanName;
private String beanName = "not.a.Spring.bean";

private Executor taskExecutor = new SimpleAsyncTaskExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ private void checkStartState() {
protected void doInitialize() {
if (this.taskScheduler == null) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setThreadNamePrefix(getBeanName() + "-consumerMonitor-");
threadPoolTaskScheduler.setThreadNamePrefix(getListenerId() + "-consumerMonitor-");
threadPoolTaskScheduler.afterPropertiesSet();
this.taskScheduler = threadPoolTaskScheduler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,29 @@ public void testMonitorCancelsAfterTargetChannelChanges() throws Exception {
container.stop();
}

@Test
void monitorTaskThreadName() {
DirectMessageListenerContainer container = new DirectMessageListenerContainer(mock(ConnectionFactory.class));
assertThat(container.getListenerId()).isEqualTo("not.a.Spring.bean");
container.setBeanName("aBean");
assertThat(container.getListenerId()).isEqualTo("aBean");
container.setListenerId("id");
assertThat(container.getListenerId()).isEqualTo("id");
container.afterPropertiesSet();
assertThat(container).extracting("taskScheduler")
.extracting("threadNamePrefix")
.asString()
.startsWith("id-consumerMonitor");

container = new DirectMessageListenerContainer(mock(ConnectionFactory.class));
container.setBeanName("aBean");
container.afterPropertiesSet();
assertThat(container).extracting("taskScheduler")
.extracting("threadNamePrefix")
.asString()
.startsWith("aBean-consumerMonitor");
}

private Envelope envelope(long tag) {
return new Envelope(tag, false, "", "");
}
Expand Down

0 comments on commit 0ccfcbe

Please sign in to comment.