From 7d3f42b27bd0042f1461e3e2ef45bbd641b05fa3 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 15 Mar 2021 17:58:43 +0100 Subject: [PATCH] Expose endpoint id as listener container name (for transaction/thread name) Closes gh-26683 --- .../jms/config/AbstractJmsListenerEndpoint.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java index 52d584a21bdc..242e7344a8d5 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerEndpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig; import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager; import org.springframework.lang.Nullable; +import org.springframework.util.StringUtils; /** * Base model for a JMS listener endpoint. @@ -50,10 +51,16 @@ public abstract class AbstractJmsListenerEndpoint implements JmsListenerEndpoint private String concurrency; + /** + * Set a custom id for this endpoint. + */ public void setId(String id) { this.id = id; } + /** + * Return the id of this endpoint (possibly generated). + */ @Override public String getId() { return this.id; @@ -136,6 +143,9 @@ public void setupListenerContainer(MessageListenerContainer listenerContainer) { } private void setupJmsListenerContainer(AbstractMessageListenerContainer listenerContainer) { + if (StringUtils.hasText(getId())) { + listenerContainer.setBeanName(getId()); + } if (getDestination() != null) { listenerContainer.setDestinationName(getDestination()); }