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.messaging.core;
018
019import org.springframework.lang.Nullable;
020import org.springframework.messaging.Message;
021import org.springframework.messaging.MessagingException;
022
023/**
024 * Operations for receiving messages from a destination.
025 *
026 * @author Mark Fisher
027 * @author Rossen Stoyanchev
028 * @since 4.0
029 * @param <D> the type of destination
030 * @see GenericMessagingTemplate
031 */
032public interface MessageReceivingOperations<D> {
033
034        /**
035         * Receive a message from a default destination.
036         * @return the received message, possibly {@code null} if the message could not
037         * be received, for example due to a timeout
038         */
039        @Nullable
040        Message<?> receive() throws MessagingException;
041
042        /**
043         * Receive a message from the given destination.
044         * @param destination the target destination
045         * @return the received message, possibly {@code null} if the message could not
046         * be received, for example due to a timeout
047         */
048        @Nullable
049        Message<?> receive(D destination) throws MessagingException;
050
051        /**
052         * Receive a message from a default destination and convert its payload to the
053         * specified target class.
054         * @param targetClass the target class to convert the payload to
055         * @return the converted payload of the reply message, possibly {@code null} if
056         * the message could not be received, for example due to a timeout
057         */
058        @Nullable
059        <T> T receiveAndConvert(Class<T> targetClass) throws MessagingException;
060
061        /**
062         * Receive a message from the given destination and convert its payload to the
063         * specified target class.
064         * @param destination the target destination
065         * @param targetClass the target class to convert the payload to
066         * @return the converted payload of the reply message, possibly {@code null} if
067         * the message could not be received, for example due to a timeout
068         */
069        @Nullable
070        <T> T receiveAndConvert(D destination, Class<T> targetClass) throws MessagingException;
071
072}