Revise generated default name for @JmsListener subscription
The previous commit changed the generated default name for a JMS subscription to <FQCN>#<method name> -- for example: - org.example.MyListener#myListenerMethod However, the JMS spec does not guarantee that '#' is a supported character. This commit therefore changes '#' to '.' as the separator between the class name and method name -- for example: - org.example.MyListener.myListenerMethod This commit also introduces tests and documentation for these changes. See gh-29790
This commit is contained in:
@@ -79,6 +79,7 @@ import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
* <em>composed annotations</em> with attribute overrides.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
* @since 4.1
|
||||
* @see EnableJms
|
||||
* @see JmsListenerAnnotationBeanPostProcessor
|
||||
@@ -113,6 +114,12 @@ public @interface JmsListener {
|
||||
|
||||
/**
|
||||
* The name for the durable subscription, if any.
|
||||
* <p>As of Spring Framework 6.0.5, if an explicit subscription name is not
|
||||
* specified, a default subscription name will be generated based on the fully
|
||||
* qualified name of the annotated listener method — for example,
|
||||
* {@code "org.example.jms.ProductListener.processRequest"} for a
|
||||
* {@code processRequest(...)} listener method in the
|
||||
* {@code org.example.jms.ProductListener} class.
|
||||
*/
|
||||
String subscription() default "";
|
||||
|
||||
|
||||
@@ -43,6 +43,10 @@ import org.springframework.util.Assert;
|
||||
* are provided as additional arguments so that these can be injected as
|
||||
* method arguments if necessary.
|
||||
*
|
||||
* <p>As of Spring Framework 6.0.5, {@code MessagingMessageListenerAdapter} implements
|
||||
* {@link SubscriptionNameProvider} in order to provide a meaningful default
|
||||
* subscription name. See {@link #getSubscriptionName()} for details.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
* @since 4.1
|
||||
@@ -70,16 +74,6 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis
|
||||
return this.handlerMethod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubscriptionName() {
|
||||
if (this.handlerMethod != null) {
|
||||
return this.handlerMethod.getBeanType().getName() + "#" + this.handlerMethod.getMethod().getName();
|
||||
}
|
||||
else {
|
||||
return this.getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onMessage(jakarta.jms.Message jmsMessage, @Nullable Session session) throws JMSException {
|
||||
@@ -145,4 +139,28 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a subscription name for this {@code MessageListener} adapter based
|
||||
* on the following rules.
|
||||
* <ul>
|
||||
* <li>If the {@link #setHandlerMethod(InvocableHandlerMethod) handlerMethod}
|
||||
* has been set, the generated subscription name takes the form of
|
||||
* {@code handlerMethod.getBeanType().getName() + "." + handlerMethod.getMethod().getName()}.</li>
|
||||
* <li>Otherwise, the generated subscription name is the result of invoking
|
||||
* {@code getClass().getName()}, which aligns with the default behavior of
|
||||
* {@link org.springframework.jms.listener.AbstractMessageListenerContainer}.</li>
|
||||
* </ul>
|
||||
* @since 6.0.5
|
||||
* @see SubscriptionNameProvider#getSubscriptionName()
|
||||
*/
|
||||
@Override
|
||||
public String getSubscriptionName() {
|
||||
if (this.handlerMethod != null) {
|
||||
return this.handlerMethod.getBeanType().getName() + "." + this.handlerMethod.getMethod().getName();
|
||||
}
|
||||
else {
|
||||
return getClass().getName();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user