Skip to content

Commit e17f267

Browse files
authored
INT-2436: JMS channel: bean name for container (#3565)
JIRA: https://jira.spring.io/browse/INT-2436 The `JmsChannelFactoryBean` creates a `ListenerContainer` internally without any `beanName` propagation. When we rely on a default internal `Executor`, it is created with a default thread name prefix for all the JMS channel instances. It cause a confusion in logs * Set `beanName` for the internal `ListenerContainer` to `this.beanName + ".container"` making its connection with a channel it is associated with and unique thread name prefix * Comment out `allWarningsAsErrors = true` in `build.gradle` for deprecated Kotlin language version `1.3`. Otherwise IDEA doesn't want to build project
1 parent 6b98192 commit e17f267

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ configure(javaProjects) { subproject ->
206206
languageVersion = '1.3'
207207
jvmTarget = '1.8'
208208
freeCompilerArgs = ['-Xjsr305=strict']
209-
allWarningsAsErrors = true
209+
// allWarningsAsErrors = true TODO bring it back after upgrading to Kotlin 1.5 language version
210210
}
211211
}
212212
compileTestKotlin {

spring-integration-jms/src/main/java/org/springframework/integration/jms/config/JmsChannelFactoryBean.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,8 +66,6 @@ public class JmsChannelFactoryBean extends AbstractFactoryBean<AbstractJmsChanne
6666

6767
private final JmsTemplate jmsTemplate = new DynamicJmsTemplate();
6868

69-
private AbstractMessageListenerContainer listenerContainer;
70-
7169
private Class<? extends AbstractMessageListenerContainer> containerType;
7270

7371
private boolean acceptMessagesWhileStopping;
@@ -376,9 +374,9 @@ public Class<?> getObjectType() {
376374
protected AbstractJmsChannel createInstance() {
377375
this.initializeJmsTemplate();
378376
if (this.messageDriven) {
379-
this.listenerContainer = createContainer();
377+
AbstractMessageListenerContainer listenerContainer = createContainer();
380378
SubscribableJmsChannel subscribableJmsChannel =
381-
new SubscribableJmsChannel(this.listenerContainer, this.jmsTemplate);
379+
new SubscribableJmsChannel(listenerContainer, this.jmsTemplate);
382380
subscribableJmsChannel.setMaxSubscribers(this.maxSubscribers);
383381
this.channel = subscribableJmsChannel;
384382
}
@@ -414,6 +412,7 @@ private AbstractMessageListenerContainer createContainer() {
414412
this.containerType = DefaultMessageListenerContainer.class;
415413
}
416414
AbstractMessageListenerContainer container = BeanUtils.instantiateClass(this.containerType);
415+
container.setBeanName(this.beanName + ".container");
417416
container.setAcceptMessagesWhileStopping(this.acceptMessagesWhileStopping);
418417
container.setAutoStartup(this.autoStartup);
419418
container.setClientId(this.clientId);
@@ -436,8 +435,6 @@ private AbstractMessageListenerContainer createContainer() {
436435
container.setSubscriptionDurable(this.subscriptionDurable);
437436
container.setSubscriptionShared(this.subscriptionShared);
438437

439-
440-
441438
if (container instanceof DefaultMessageListenerContainer) {
442439
DefaultMessageListenerContainer dmlc = (DefaultMessageListenerContainer) container;
443440
JavaUtils.INSTANCE

spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ public void queueNameChannel() {
150150
assertThat(TestUtils.getPropertyValue(
151151
TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue())
152152
.isEqualTo(1);
153+
assertThat(TestUtils.getPropertyValue(container, "taskExecutor.threadNamePrefix"))
154+
.isEqualTo("queueNameChannel.container-");
153155
}
154156

155157
@Test

0 commit comments

Comments
 (0)