Class JmsOutboundGateway

All Implemented Interfaces:
MessageListener, org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Lifecycle, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, MessageProducer, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, ManageableLifecycle, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class JmsOutboundGateway extends AbstractReplyProducingMessageHandler implements ManageableLifecycle, MessageListener
An outbound Messaging Gateway for request/reply JMS.
Author:
Mark Fisher, Arjen Poutsma, Juergen Hoeller, Oleg Zhurakousky, Gary Russell, Artem Bilan, Christian Tzolov
  • Field Details

    • DEFAULT_RECEIVE_TIMEOUT

      public static final long DEFAULT_RECEIVE_TIMEOUT
      A default receive timeout in milliseconds.
      See Also:
  • Constructor Details

    • JmsOutboundGateway

      public JmsOutboundGateway()
  • Method Details

    • setDeliveryPersistent

      public void setDeliveryPersistent(boolean deliveryPersistent)
      Set whether message delivery should be persistent or non-persistent, specified as a boolean value ("true" or "false"). This will set the delivery mode accordingly to either "PERSISTENT" (1) or "NON_PERSISTENT" (2).

      The default is "true", i.e. delivery mode "PERSISTENT".

      Parameters:
      deliveryPersistent - true for a persistent delivery.
      See Also:
    • setConnectionFactory

      public void setConnectionFactory(ConnectionFactory connectionFactory)
      Set the JMS ConnectionFactory that this gateway should use. This is a required property.
      Parameters:
      connectionFactory - The connection factory.
    • setRequestDestination

      public void setRequestDestination(Destination requestDestination)
      Set the JMS Destination to which request Messages should be sent. Either this or one of 'requestDestinationName' or 'requestDestinationExpression' is required.
      Parameters:
      requestDestination - The request destination.
    • setRequestDestinationName

      public void setRequestDestinationName(String requestDestinationName)
      Set the name of the JMS Destination to which request Messages should be sent. Either this or one of 'requestDestination' or 'requestDestinationExpression' is required.
      Parameters:
      requestDestinationName - The request destination name.
    • setRequestDestinationExpression

      public void setRequestDestinationExpression(Expression requestDestinationExpression)
      Set the SpEL Expression to be used for determining the request Destination instance or request destination name. Either this or one of 'requestDestination' or 'requestDestinationName' is required.
      Parameters:
      requestDestinationExpression - The request destination expression.
    • setReplyDestination

      public void setReplyDestination(Destination replyDestination)
      Set the JMS Destination from which reply Messages should be received. If none is provided, this gateway will create a TemporaryQueue per invocation.
      Parameters:
      replyDestination - The reply destination.
    • setReplyDestinationName

      public void setReplyDestinationName(String replyDestinationName)
      Set the name of the JMS Destination from which reply Messages should be received. If none is provided, this gateway will create a TemporaryQueue per invocation.
      Parameters:
      replyDestinationName - The reply destination name.
    • setReplyDestinationExpression

      public void setReplyDestinationExpression(Expression replyDestinationExpression)
      Set the SpEL Expression to be used for determining the reply Destination instance or reply destination name. Either this or one of 'replyDestination' or 'replyDestinationName' is required.
      Parameters:
      replyDestinationExpression - The reply destination expression.
    • setDestinationResolver

      public void setDestinationResolver(DestinationResolver destinationResolver)
      Provide the DestinationResolver to use when resolving either a 'requestDestinationName' or 'replyDestinationName' value. The default is an instance of DynamicDestinationResolver.
      Parameters:
      destinationResolver - The destination resolver.
    • setRequestPubSubDomain

      public void setRequestPubSubDomain(boolean requestPubSubDomain)
      Specify whether the request destination is a Topic. This value is necessary when providing a destination name for a Topic rather than a destination reference.
      Parameters:
      requestPubSubDomain - true if the request destination is a Topic.
    • setReplyPubSubDomain

      public void setReplyPubSubDomain(boolean replyPubSubDomain)
      Specify whether the reply destination is a Topic. This value is necessary when providing a destination name for a Topic rather than a destination reference.
      Parameters:
      replyPubSubDomain - true if the reply destination is a Topic.
    • setReceiveTimeout

      public void setReceiveTimeout(long receiveTimeout)
      Set the max timeout value for the MessageConsumer's receive call when waiting for a reply. The default value is 5 seconds.
      Parameters:
      receiveTimeout - The receive timeout.
    • setDefaultPriority

      public void setDefaultPriority(int priority)
      Specify the default JMS priority to use when sending request Messages with no IntegrationMessageHeaderAccessor.PRIORITY header. The value should be within the range of 0-9.
      Parameters:
      priority - The priority.
      Since:
      5.1.2
    • setTimeToLive

      public void setTimeToLive(long timeToLive)
      Specify the timeToLive for each sent Message. The default value indicates no expiration.
      Parameters:
      timeToLive - The time to live.
    • setExplicitQosEnabled

      public void setExplicitQosEnabled(boolean explicitQosEnabled)
      Specify whether explicit QoS settings are enabled (deliveryMode, priority, and timeToLive).
      Parameters:
      explicitQosEnabled - true to enable explicit QoS.
    • setCorrelationKey

      public void setCorrelationKey(String correlationKey)
      Provide the name of a JMS property that should hold a generated UUID that the receiver of the JMS Message would expect to represent the CorrelationID. When waiting for the reply Message, a MessageSelector will be configured to match this property name and the UUID value that was sent in the request.

      If this value is NULL (the default) then the reply consumer's MessageSelector will be expecting the JMSCorrelationID to equal the Message ID of the request.

      If you want to store the outbound correlation UUID value in the actual JMSCorrelationID property, then set this value to "JMSCorrelationID".

      If you want to use and existing "JMSCorrelationID" from the inbound message (mapped from 'jms_correlationId'), you can set this property to "JMSCorrelationID*" with the trailing asterisk. If the message has a correlation id, it will be used, otherwise a new one will be set in the 'JMSCorrelationID' header. However, understand that the gateway has no means to ensure uniqueness and unexpected side effects can occur if the correlation id is not unique.

      This setting is not allowed if a reply listener is used.

      Parameters:
      correlationKey - The correlation key.
    • setMessageConverter

      public void setMessageConverter(MessageConverter messageConverter)
      Provide a MessageConverter strategy to use for converting the Spring Integration request Message into a JMS Message and for converting the JMS reply Messages back into Spring Integration Messages.

      The default is SimpleMessageConverter.

      Parameters:
      messageConverter - The message converter.
    • setHeaderMapper

      public void setHeaderMapper(JmsHeaderMapper headerMapper)
      Provide a JmsHeaderMapper implementation for mapping the Spring Integration Message Headers to/from JMS Message properties.
      Parameters:
      headerMapper - The header mapper.
    • setExtractRequestPayload

      public void setExtractRequestPayload(boolean extractRequestPayload)
      This property describes how a JMS Message should be generated from the Spring Integration Message. If set to 'true', the body of the JMS Message will be created from the Spring Integration Message's payload (via the MessageConverter). If set to 'false', then the entire Spring Integration Message will serve as the base for JMS Message creation. Since the JMS Message is created by the MessageConverter, this really manages what is sent to the MessageConverter: the entire Spring Integration Message or only its payload. Default is 'true'.
      Parameters:
      extractRequestPayload - true to extract the request payload.
    • setExtractReplyPayload

      public void setExtractReplyPayload(boolean extractReplyPayload)
      This property describes what to do with a JMS reply Message. If set to 'true', the payload of the Spring Integration Message will be created from the JMS Reply Message's body (via MessageConverter). Otherwise, the entire JMS Message will become the payload of the Spring Integration Message.
      Parameters:
      extractReplyPayload - true to extract the reply payload.
    • setReplyChannel

      public void setReplyChannel(MessageChannel replyChannel)
      Specify the Spring Integration reply channel. If this property is not set the gateway will check for a 'replyChannel' header on the request.
      Parameters:
      replyChannel - The reply channel.
    • setReplyContainerProperties

      public void setReplyContainerProperties(JmsOutboundGateway.ReplyContainerProperties replyContainerProperties)
      Parameters:
      replyContainerProperties - the replyContainerProperties to set
    • getComponentType

      public String getComponentType()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this method to provide component type information.
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • setUseReplyContainer

      public void setUseReplyContainer(boolean useReplyContainer)
      Parameters:
      useReplyContainer - the useReplyContainer to set
    • setRequiresReply

      public void setRequiresReply(boolean requiresReply)
      Description copied from class: AbstractReplyProducingMessageHandler
      Flag whether a reply is required. If true an incoming message MUST result in a reply message being sent. If false an incoming message MAY result in a reply message being sent. Default is false.
      Overrides:
      setRequiresReply in class AbstractReplyProducingMessageHandler
      Parameters:
      requiresReply - true if a reply is required.
    • setIdleReplyContainerTimeout

      public void setIdleReplyContainerTimeout(long idleReplyContainerTimeout)
      Set the target timeout for idle containers, in seconds. Setting this greater than zero enables lazy starting of the reply listener container. The container will be started when a message is sent. It will be stopped when idle for at least this time. The actual stop time may be up to 1.5x this time.
      Parameters:
      idleReplyContainerTimeout - the timeout in seconds.
      Since:
      4.2
    • setIdleReplyContainerTimeout

      public void setIdleReplyContainerTimeout(long idleReplyContainerTimeout, TimeUnit unit)
      Set the target timeout for idle containers. Setting this greater than zero enables lazy starting of the reply listener container. The container will be started when a message is sent. It will be stopped when idle for at least this time. The actual stop time may be up to 1.5x this time.
      Parameters:
      idleReplyContainerTimeout - the timeout in seconds.
      unit - the time unit.
      Since:
      4.2
    • doInit

      protected void doInit()
      Overrides:
      doInit in class AbstractReplyProducingMessageHandler
    • start

      public void start()
      Specified by:
      start in interface Lifecycle
      Specified by:
      start in interface ManageableLifecycle
    • stop

      public void stop()
      Specified by:
      stop in interface Lifecycle
      Specified by:
      stop in interface ManageableLifecycle
    • isRunning

      public boolean isRunning()
      Specified by:
      isRunning in interface Lifecycle
      Specified by:
      isRunning in interface ManageableLifecycle
    • handleRequestMessage

      protected Object handleRequestMessage(Message<?> requestMessage)
      Description copied from class: AbstractReplyProducingMessageHandler
      Subclasses must implement this method to handle the request Message. The return value may be a Message, a MessageBuilder, or any plain Object. The base class will handle the final creation of a reply Message from any of those starting points. If the return value is null, the Message flow will end here.
      Specified by:
      handleRequestMessage in class AbstractReplyProducingMessageHandler
      Parameters:
      requestMessage - The request message.
      Returns:
      The result of handling the message, or null.
    • createConnection

      protected Connection createConnection() throws JMSException
      Create a new JMS Connection for this JMS gateway.
      Returns:
      The connection.
      Throws:
      JMSException - Any JMSException.
    • createSession

      protected Session createSession(Connection connection) throws JMSException
      Create a new JMS Session using the provided Connection.
      Parameters:
      connection - The connection.
      Returns:
      The session.
      Throws:
      JMSException - Any JMSException.
    • onMessage

      public void onMessage(Message message)
      Specified by:
      onMessage in interface MessageListener