org.springframework.jms.listener

Class AbstractPollingMessageListenerContainer

    • Field Detail

      • DEFAULT_RECEIVE_TIMEOUT

        public static final long DEFAULT_RECEIVE_TIMEOUT
        The default receive timeout: 1000 ms = 1 second.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractPollingMessageListenerContainer

        public AbstractPollingMessageListenerContainer()
    • Method Detail

      • setSessionTransacted

        public void setSessionTransacted(boolean sessionTransacted)
        Description copied from class: JmsAccessor
        Set the transaction mode that is used when creating a JMS Session. Default is "false".

        Note that within a JTA transaction, the parameters passed to create(Queue/Topic)Session(boolean transacted, int acknowledgeMode) method are not taken into account. Depending on the Java EE transaction context, the container makes its own decisions on these values. Analogously, these parameters are not taken into account within a locally managed transaction either, since the accessor operates on an existing JMS Session in this case.

        Setting this flag to "true" will use a short local JMS transaction when running outside of a managed transaction, and a synchronized local JMS transaction in case of a managed transaction (other than an XA transaction) being present. This has the effect of a local JMS transaction being managed alongside the main transaction (which might be a native JDBC transaction), with the JMS transaction committing right after the main transaction.

        Overrides:
        setSessionTransacted in class JmsAccessor
        See Also:
        Connection.createSession(boolean, int)
      • getTransactionManager

        @Nullable
        protected final PlatformTransactionManager getTransactionManager()
        Return the Spring PlatformTransactionManager to use for transactional wrapping of message reception plus listener execution.
      • setTransactionName

        public void setTransactionName(java.lang.String transactionName)
        Specify the transaction name to use for transactional wrapping. Default is the bean name of this listener container, if any.
        See Also:
        TransactionDefinition.getName()
      • setTransactionTimeout

        public void setTransactionTimeout(int transactionTimeout)
        Specify the transaction timeout to use for transactional wrapping, in seconds. Default is none, using the transaction manager's default timeout.
        See Also:
        TransactionDefinition.getTimeout(), setReceiveTimeout(long)
      • getReceiveTimeout

        protected long getReceiveTimeout()
        Return the receive timeout (ms) configured for this listener container.
        Since:
        4.2
      • isSessionLocallyTransacted

        protected boolean isSessionLocallyTransacted(Session session)
        This implementation checks whether the Session is externally synchronized. In this case, the Session is not locally transacted, despite the listener container's "sessionTransacted" flag being set to "true".
        Overrides:
        isSessionLocallyTransacted in class AbstractMessageListenerContainer
        Parameters:
        session - the Session to check
        Returns:
        whether the given Session is locally transacted
        See Also:
        JmsResourceHolder
      • receiveMessage

        @Nullable
        protected Message receiveMessage(MessageConsumer consumer)
                                            throws JMSException
        Receive a message from the given consumer.
        Parameters:
        consumer - the MessageConsumer to use
        Returns:
        the Message, or null if none
        Throws:
        JMSException - if thrown by JMS methods
      • messageReceived

        protected void messageReceived(java.lang.Object invoker,
                                       Session session)
        Template method that gets called right when a new message has been received, before attempting to process it. Allows subclasses to react to the event of an actual incoming message, for example adapting their consumer count.
        Parameters:
        invoker - the invoker object (passed through)
        session - the receiving JMS Session
      • noMessageReceived

        protected void noMessageReceived(java.lang.Object invoker,
                                         Session session)
        Template method that gets called when no message has been received, before returning to the receive loop again. Allows subclasses to react to the event of no incoming message, for example marking the invoker as idle.
        Parameters:
        invoker - the invoker object (passed through)
        session - the receiving JMS Session
      • getConnection

        @Nullable
        protected Connection getConnection(JmsResourceHolder holder)
        Fetch an appropriate Connection from the given JmsResourceHolder.

        This implementation accepts any JMS 1.1 Connection.

        Parameters:
        holder - the JmsResourceHolder
        Returns:
        an appropriate Connection fetched from the holder, or null if none found
      • getSession

        @Nullable
        protected Session getSession(JmsResourceHolder holder)
        Fetch an appropriate Session from the given JmsResourceHolder.

        This implementation accepts any JMS 1.1 Session.

        Parameters:
        holder - the JmsResourceHolder
        Returns:
        an appropriate Session fetched from the holder, or null if none found