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