001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jms.listener;
018
019import javax.jms.JMSException;
020import javax.jms.Message;
021import javax.jms.Session;
022
023/**
024 * Variant of the standard JMS {@link javax.jms.MessageListener} interface,
025 * offering not only the received Message but also the underlying
026 * JMS Session object. The latter can be used to send reply messages,
027 * without the need to access an external Connection/Session,
028 * i.e. without the need to access the underlying ConnectionFactory.
029 *
030 * <p>Supported by Spring's {@link DefaultMessageListenerContainer}
031 * and {@link SimpleMessageListenerContainer},
032 * as direct alternative to the standard JMS MessageListener interface.
033 * Typically <i>not</i> supported by JCA-based listener containers:
034 * For maximum compatibility, implement a standard JMS MessageListener instead.
035 *
036 * @author Juergen Hoeller
037 * @since 2.0
038 * @param <M> the message type
039 * @see AbstractMessageListenerContainer#setMessageListener
040 * @see DefaultMessageListenerContainer
041 * @see SimpleMessageListenerContainer
042 * @see org.springframework.jms.listener.endpoint.JmsMessageEndpointManager
043 * @see javax.jms.MessageListener
044 */
045@FunctionalInterface
046public interface SessionAwareMessageListener<M extends Message> {
047
048        /**
049         * Callback for processing a received JMS message.
050         * <p>Implementors are supposed to process the given Message,
051         * typically sending reply messages through the given Session.
052         * @param message the received JMS message (never {@code null})
053         * @param session the underlying JMS Session (never {@code null})
054         * @throws JMSException if thrown by JMS methods
055         */
056        void onMessage(M message, Session session) throws JMSException;
057
058}