From 1c17ddb121bb875ac5e537159b0960d4a41b8526 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 12 Mar 2010 19:02:14 +0000 Subject: [PATCH] INT-890 Added QoS attributes (priority, time-to-live, delivery-persistent, and explicit-qos-enabled) to the 'outbound-channel-adapter' element. Also added an 'explicit-qos-enabled' boolean to the 'outbound-gateway' element which now must be set to true to enable the use of its QoS settings. --- .../jms/AbstractJmsTemplateBasedAdapter.java | 49 +++++++++++++++++++ .../integration/jms/JmsOutboundGateway.java | 21 ++++++-- .../jms/JmsSendingMessageHandler.java | 2 +- .../JmsOutboundChannelAdapterParser.java | 4 ++ .../jms/config/JmsOutboundGatewayParser.java | 3 +- .../jms/config/spring-integration-jms-2.0.xsd | 13 +++++ .../JmsOutboundChannelAdapterParserTests.java | 29 ++++++++++- .../jms/config/jmsOutboundWithQos.xml | 32 ++++++++++++ 8 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/jmsOutboundWithQos.xml diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java index 2a1fa17ac7..0498836815 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java @@ -17,6 +17,7 @@ package org.springframework.integration.jms; import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; import javax.jms.Destination; import org.springframework.beans.factory.InitializingBean; @@ -41,6 +42,14 @@ public abstract class AbstractJmsTemplateBasedAdapter implements InitializingBea private volatile DestinationResolver destinationResolver; + private volatile int deliveryMode = javax.jms.Message.DEFAULT_DELIVERY_MODE; + + private volatile long timeToLive = javax.jms.Message.DEFAULT_TIME_TO_LIVE; + + private volatile int priority = javax.jms.Message.DEFAULT_PRIORITY; + + private volatile boolean explicitQosEnabled; + private volatile JmsTemplate jmsTemplate; private volatile JmsHeaderMapper headerMapper; @@ -100,6 +109,42 @@ public abstract class AbstractJmsTemplateBasedAdapter implements InitializingBea this.headerMapper = headerMapper; } + /** + * @see JmsTemplate#setExplicitQosEnabled(boolean) + */ + public void setExplicitQosEnabled(boolean explicitQosEnabled) { + this.explicitQosEnabled = explicitQosEnabled; + } + + /** + * @see JmsTemplate#setTimeToLive(long) + */ + public void setTimeToLive(long timeToLive) { + this.timeToLive = timeToLive; + } + + /** + * @see JmsTemplate#setDeliveryMode(int) + */ + public void setDeliveryMode(int deliveryMode) { + this.deliveryMode = deliveryMode; + } + + /** + * @see JmsTemplate#setDeliveryPersistent(boolean) + */ + public void setDeliveryPersistent(boolean deliveryPersistent) { + this.deliveryMode = deliveryPersistent ? + DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT; + } + + /** + * @see JmsTemplate#setPriority(int) + */ + public void setPriority(int priority) { + this.priority = priority; + } + protected JmsTemplate getJmsTemplate() { if (this.jmsTemplate == null) { this.afterPropertiesSet(); @@ -119,6 +164,10 @@ public abstract class AbstractJmsTemplateBasedAdapter implements InitializingBea + " 'destination' (or 'destination-name') are required."); this.jmsTemplate = this.createDefaultJmsTemplate(); } + this.jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled); + this.jmsTemplate.setTimeToLive(this.timeToLive); + this.jmsTemplate.setPriority(this.priority); + this.jmsTemplate.setDeliveryMode(this.deliveryMode); this.configureMessageConverter(this.jmsTemplate, this.headerMapper); this.initialized = true; } diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java index 2f6d339e04..aa7edf2298 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java @@ -72,6 +72,8 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler { private volatile int priority = javax.jms.Message.DEFAULT_PRIORITY; + private volatile boolean explicitQosEnabled; + private ConnectionFactory connectionFactory; private volatile MessageConverter messageConverter; @@ -181,6 +183,14 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler { this.timeToLive = timeToLive; } + /** + * Specify whether explicit QoS settings are enabled + * (deliveryMode, priority, and timeToLive). + */ + public void setExplicitQosEnabled(boolean explicitQosEnabled) { + this.explicitQosEnabled = explicitQosEnabled; + } + /** * Provide a {@link MessageConverter} strategy to use for converting the * Spring Integration request Message into a JMS Message and for converting @@ -312,13 +322,16 @@ public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler { session = createSession(connection); javax.jms.Message jmsRequest = this.messageConverter.toMessage(requestMessage, session); messageProducer = session.createProducer(this.getRequestDestination(session)); - messageProducer.setDeliveryMode(this.deliveryMode); - messageProducer.setPriority(this.priority); - messageProducer.setTimeToLive(this.timeToLive); replyTo = this.getReplyDestination(session); jmsRequest.setJMSReplyTo(replyTo); connection.start(); - messageProducer.send(jmsRequest); + if (this.explicitQosEnabled) { + messageProducer.send(jmsRequest, + this.deliveryMode, this.priority, this.timeToLive); + } + else { + messageProducer.send(jmsRequest); + } if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic) { messageConsumer = session.createConsumer(replyTo); } diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java index cb0f45f901..256e5250ce 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsSendingMessageHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java index fd7d33eb25..f50c65565b 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParser.java @@ -71,6 +71,10 @@ public class JmsOutboundChannelAdapterParser extends AbstractOutboundChannelAdap builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "time-to-live"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "priority"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "delivery-persistent"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "explicit-qos-enabled"); return builder.getBeanDefinition(); } diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java index dc6515b2f4..c620af08e6 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsOutboundGatewayParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -65,6 +65,7 @@ public class JmsOutboundGatewayParser extends AbstractConsumerEndpointParser { IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "delivery-mode"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "time-to-live"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "priority"); + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "explicit-qos-enabled"); return builder; } diff --git a/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd b/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd index e38d2621e7..0c1862b8c2 100644 --- a/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd +++ b/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd @@ -633,6 +633,7 @@ + @@ -701,6 +702,18 @@ + + + + Specify a boolean value indicating whether the delivery mode should be + DeliveryMode.PERSISTENT (true) or DeliveryMode.NON_PERSISTENT (false). + This setting will only take effect if 'explicit-qos-enabled' is true. + + + + + + + + + + + + + + + + + + + + + + + + +