Add back-off attribute to JMS namespace

This commit adds a "back-off" attribute to the jms:listener-container
 element so that a BackOff instance can be provided for users of the
 XML namespace.

 Issue: SPR-11746
This commit is contained in:
Stephane Nicoll
2014-05-09 15:05:43 +02:00
parent 6a0483128a
commit 49040a2925
6 changed files with 73 additions and 18 deletions

View File

@@ -54,6 +54,8 @@ class JmsListenerContainerParser extends AbstractListenerContainerParser {
private static final String RECOVERY_INTERVAL_ATTRIBUTE = "recovery-interval";
private static final String BACK_OFF_ATTRIBUTE = "back-off";
protected PropertyValues parseProperties(Element containerEle, ParserContext parserContext) {
final MutablePropertyValues properties = new MutablePropertyValues();
@@ -223,10 +225,18 @@ class JmsListenerContainerParser extends AbstractListenerContainerParser {
}
}
String recoveryInterval = containerEle.getAttribute(RECOVERY_INTERVAL_ATTRIBUTE);
if (StringUtils.hasText(recoveryInterval)) {
String backOffBeanName = containerEle.getAttribute(BACK_OFF_ATTRIBUTE);
if (StringUtils.hasText(backOffBeanName)) {
if (!isSimpleContainer) {
propertyValues.add("recoveryInterval", recoveryInterval);
propertyValues.add("backOff", new RuntimeBeanReference(backOffBeanName));
}
}
else { // No need to consider this if back-off is set
String recoveryInterval = containerEle.getAttribute(RECOVERY_INTERVAL_ATTRIBUTE);
if (StringUtils.hasText(recoveryInterval)) {
if (!isSimpleContainer) {
propertyValues.add("recoveryInterval", recoveryInterval);
}
}
}

View File

@@ -224,6 +224,8 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
* between recovery attempts. If the {@link BackOff} implementation
* returns {@link BackOff#STOP}, this listener container will not further
* attempt to recover.
* <p>The {@link #setRecoveryInterval(long) recovery interval} is ignored
* when this property is set.
*/
public void setBackOff(BackOff backOff) {
this.backOff = backOff;
@@ -231,9 +233,10 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
/**
* Specify the interval between recovery attempts, in <b>milliseconds</b>.
* The default is 5000 ms, that is, 5 seconds.
* <p>This is a convenience method to create a {@link FixedBackOff} with
* the specified interval.
* The default is 5000 ms, that is, 5 seconds. This is a convenience method
* to create a {@link FixedBackOff} with the specified interval.
* <p>For more recovery options, consider specifying a {@link BackOff}
* instance instead.
* @see #setBackOff(BackOff)
* @see #handleListenerSetupFailure
*/

View File

@@ -318,11 +318,29 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="back-off" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specify the BackOff instance to use to compute the interval between recovery
attempts. If the BackOff implementation returns "BackOff#STOP", the listener
container will not further attempt to recover. The recovery-interval value is
ignored when this property is set. The default is a FixedBackOff with an
interval of 5000 ms, that is 5 seconds.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.util.BackOff"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="recovery-interval" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specify the interval between recovery attempts, in milliseconds.
The default is 5000 ms, that is, 5 seconds.
Specify the interval between recovery attempts, in milliseconds. Convenience
way to create a FixedBackOff with the specified interval. For more recovery
options, consider specifying a BackOff instance instead. The default is
5000 ms, that is 5 seconds.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>