Skip to content

Commit 1bc41bd

Browse files
committed
Expose JMS message listener container ids
Issue: SPR-13633
1 parent cca037a commit 1bc41bd

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistry.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020
import java.util.Collections;
2121
import java.util.Map;
22+
import java.util.Set;
2223
import java.util.concurrent.ConcurrentHashMap;
2324
import java.util.concurrent.atomic.AtomicInteger;
2425

@@ -68,12 +69,21 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc
6869
* @param id the id of the container
6970
* @return the container or {@code null} if no container with that id exists
7071
* @see JmsListenerEndpoint#getId()
72+
* @see #getListenerContainerIds()
7173
*/
7274
public MessageListenerContainer getListenerContainer(String id) {
7375
Assert.notNull(id, "Container identifier must not be null");
7476
return this.listenerContainers.get(id);
7577
}
7678

79+
/**
80+
* Return the ids of the managed {@link MessageListenerContainer} instance(s).
81+
* @see #getListenerContainer(String)
82+
*/
83+
public Set<String> getListenerContainerIds() {
84+
return Collections.unmodifiableSet(this.listenerContainers.keySet());
85+
}
86+
7787
/**
7888
* Return the managed {@link MessageListenerContainer} instance(s).
7989
*/

spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public void testCustomConfiguration(ApplicationContext context) {
169169

170170
JmsListenerEndpointRegistry customRegistry =
171171
context.getBean("customRegistry", JmsListenerEndpointRegistry.class);
172+
assertEquals("Wrong number of containers in the registry", 2,
173+
customRegistry.getListenerContainerIds().size());
172174
assertEquals("Wrong number of containers in the registry", 2,
173175
customRegistry.getListenerContainers().size());
174176
assertNotNull("Container with custom id on the annotation should be found",

spring-jms/src/test/java/org/springframework/jms/config/JmsListenerEndpointRegistrarTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -76,6 +76,7 @@ public void registerNullContainerFactoryIsAllowed() throws Exception {
7676
registrar.afterPropertiesSet();
7777
assertNotNull("Container not created", registry.getListenerContainer("some id"));
7878
assertEquals(1, registry.getListenerContainers().size());
79+
assertEquals("some id", registry.getListenerContainerIds().iterator().next());
7980
}
8081

8182
@Test
@@ -98,6 +99,7 @@ public void registerContainerWithoutFactory() throws Exception {
9899
registrar.afterPropertiesSet();
99100
assertNotNull("Container not created", registry.getListenerContainer("myEndpoint"));
100101
assertEquals(1, registry.getListenerContainers().size());
102+
assertEquals("myEndpoint", registry.getListenerContainerIds().iterator().next());
101103
}
102104

103105
}

0 commit comments

Comments
 (0)