leachad opened SPR-17570 and commented
As a user of the spring-jms
artifacts, I would like to be able to register an exception listener on the container(s) that get generated using the DefaultJmsListenerContainerFactory
.
Currently, this method is not configurable in the DefaultJmsListenerContainerFactory
object but setErrorHandler
for message processing is.
Reference URL: https://stackoverflow.com/questions/53639178/why-does-defaultjmslistenercontainerfactory-not-expose-setexceptionlistener-meth/53639840#53639840
Comment From: spring-projects-issues
Stéphane Nicoll commented
There is a setErrorHandler
on AbstractJmsListenerContainerFactory
that is the parent of DefaultJmsListenerContainerFactory
so this method is exposed.
What am I missing?
Comment From: spring-projects-issues
Juergen Hoeller commented
Any particular use case for a custom ExceptionListener
there? Any need that couldn't be implemented through an ErrorHandler
through an instanceof JMSException
check?
Comment From: spring-projects-issues
leachad commented
Juergen Hoeller and Stéphane Nicoll from what I read of the spring-jms docs, the ErrorHandler is used for message handling exceptions. I'm looking at injecting a custom exception listener for connection exceptions, not for message handling exceptions
Specifically, I'm trying to hook into the exception handling that logs this error
`[DefaultMessageListenerContainer-1] ERROR o.s.jms.listener.DefaultMessageListenerContainer Could not refresh JMS Connection for destination 'my_topic_name``
I attempted to use an instance of JmsListenerConfigurer
to set the exception listener for each DMLC, but since the containers weren't yet created, this proved fruitless.
If there were some way to have inject a preStart
configuration class before startIfNecessary
is invoked:
MessageListenerContainer container = createListenerContainer(endpoint, factory);
this.listenerContainers.put(id, container);
if (startImmediately) {
startIfNecessary(container);
}
This code snippet is in JmsListenerEndpointRegistry.java:141-146 version 4.3.19.RELEASE
Comment From: spring-projects-issues
leachad commented
I was able to concoct a workaround for my use case and now have telemetry in place for monitoring connections using this exception listener.
Here's what I did. Seems to work with fine running my pub sub tests locally
public class MyContainerFactory extends DefaultJmsListenerContainerFactory {
private ExceptionListener exceptionListener;
/*
* @see
DefaultMessageListenerContainer#setExceptionListener
/
public void setExceptionListener(ExceptionListener exceptionListener) {
this.exceptionListener = exceptionListener;
}
@Override
protected DefaultMessageListenerContainer createContainerInstance() {
return new DefaultMessageListenerContainer();
}
@Override
protected void initializeContainer(DefaultMessageListenerContainer container) {
super.initializeContainer(container);
if (this.exceptionListener != null) { container.setExceptionListener(this.exceptionListener); } }
}