JMS SimpleMessageListenerContainer silently falls back to lazy registration of consumers ()
This commit is contained in:
parent
4a63a5b3ba
commit
3fdbe1081d
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -62,6 +62,8 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
|
|
||||||
private boolean pubSubNoLocal = false;
|
private boolean pubSubNoLocal = false;
|
||||||
|
|
||||||
|
private boolean connectLazily = false;
|
||||||
|
|
||||||
private int concurrentConsumers = 1;
|
private int concurrentConsumers = 1;
|
||||||
|
|
||||||
private Executor taskExecutor;
|
private Executor taskExecutor;
|
||||||
|
|
@ -89,6 +91,20 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
return this.pubSubNoLocal;
|
return this.pubSubNoLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify whether to connect lazily, i.e. whether to establish the JMS Connection
|
||||||
|
* and the corresponding Sessions and MessageConsumers as late as possible -
|
||||||
|
* in the start phase of this container.
|
||||||
|
* <p>Default is "false": connecting early, i.e. during the bean initialization phase.
|
||||||
|
* Set this flag to "true" in order to switch to lazy connecting if your target broker
|
||||||
|
* is likely to not have started up yet and you prefer to not even try a connection.
|
||||||
|
* @see #start()
|
||||||
|
* @see #initialize()
|
||||||
|
*/
|
||||||
|
public void setConnectLazily(boolean connectLazily) {
|
||||||
|
this.connectLazily = connectLazily;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify concurrency limits via a "lower-upper" String, e.g. "5-10", or a simple
|
* Specify concurrency limits via a "lower-upper" String, e.g. "5-10", or a simple
|
||||||
* upper limit String, e.g. "10".
|
* upper limit String, e.g. "10".
|
||||||
|
|
@ -159,6 +175,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
this.taskExecutor = taskExecutor;
|
this.taskExecutor = taskExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void validateConfiguration() {
|
protected void validateConfiguration() {
|
||||||
super.validateConfiguration();
|
super.validateConfiguration();
|
||||||
if (isSubscriptionDurable() && this.concurrentConsumers != 1) {
|
if (isSubscriptionDurable() && this.concurrentConsumers != 1) {
|
||||||
|
|
@ -174,6 +191,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
/**
|
/**
|
||||||
* Always use a shared JMS Connection.
|
* Always use a shared JMS Connection.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected final boolean sharedConnectionEnabled() {
|
protected final boolean sharedConnectionEnabled() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -183,15 +201,25 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
* in the form of a JMS Session plus associated MessageConsumer.
|
* in the form of a JMS Session plus associated MessageConsumer.
|
||||||
* @see #createListenerConsumer
|
* @see #createListenerConsumer
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void doInitialize() throws JMSException {
|
protected void doInitialize() throws JMSException {
|
||||||
|
if (!this.connectLazily) {
|
||||||
|
try {
|
||||||
establishSharedConnection();
|
establishSharedConnection();
|
||||||
|
}
|
||||||
|
catch (JMSException ex) {
|
||||||
|
logger.debug("Could not connect on initialization - registering message consumers lazily", ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
initializeConsumers();
|
initializeConsumers();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-initializes this container's JMS message consumers,
|
* Re-initializes this container's JMS message consumers,
|
||||||
* if not initialized already.
|
* if not initialized already.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void doStart() throws JMSException {
|
protected void doStart() throws JMSException {
|
||||||
super.doStart();
|
super.doStart();
|
||||||
initializeConsumers();
|
initializeConsumers();
|
||||||
|
|
@ -200,6 +228,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
/**
|
/**
|
||||||
* Registers this listener container as JMS ExceptionListener on the shared connection.
|
* Registers this listener container as JMS ExceptionListener on the shared connection.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void prepareSharedConnection(Connection connection) throws JMSException {
|
protected void prepareSharedConnection(Connection connection) throws JMSException {
|
||||||
super.prepareSharedConnection(connection);
|
super.prepareSharedConnection(connection);
|
||||||
connection.setExceptionListener(this);
|
connection.setExceptionListener(this);
|
||||||
|
|
@ -320,6 +349,7 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta
|
||||||
/**
|
/**
|
||||||
* Destroy the registered JMS Sessions and associated MessageConsumers.
|
* Destroy the registered JMS Sessions and associated MessageConsumers.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
protected void doShutdown() throws JMSException {
|
protected void doShutdown() throws JMSException {
|
||||||
logger.debug("Closing JMS MessageConsumers");
|
logger.debug("Closing JMS MessageConsumers");
|
||||||
for (MessageConsumer consumer : this.consumers) {
|
for (MessageConsumer consumer : this.consumers) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue