001/*
002 * Copyright 2002-2013 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 java.util.Map;
020
021import org.springframework.messaging.Message;
022import org.springframework.messaging.MessagingException;
023
024/**
025 * Extends {@link MessageRequestReplyOperations} and adds operations for sending and
026 * receiving messages to and from a destination specified as a (resolvable) String name.
027 *
028 * @author Mark Fisher
029 * @author Rossen Stoyanchev
030 * @since 4.0
031 * @see DestinationResolver
032 */
033public interface DestinationResolvingMessageRequestReplyOperations<D> extends MessageRequestReplyOperations<D> {
034
035        /**
036         * Resolve the given destination name to a destination and send the given message,
037         * receive a reply and return it.
038         * @param destinationName the name of the target destination
039         * @param requestMessage the mesage to send
040         * @return the received message, possibly {@code null} if the message could not
041         * be received, for example due to a timeout
042         */
043        Message<?> sendAndReceive(String destinationName, Message<?> requestMessage) throws MessagingException;
044
045        /**
046         * Resolve the given destination name, convert the payload request Object
047         * to serialized form, possibly using a
048         * {@link org.springframework.messaging.converter.MessageConverter},
049         * wrap it as a message and send it to the resolved destination, receive a reply
050         * and convert its body to the specified target class.
051         * @param destinationName the name of the target destination
052         * @param request the payload for the request message to send
053         * @param targetClass the target class to convert the payload of the reply to
054         * @return the converted payload of the reply message, possibly {@code null} if
055         * the message could not be received, for example due to a timeout
056         */
057        <T> T convertSendAndReceive(String destinationName, Object request, Class<T> targetClass)
058                        throws MessagingException;
059
060        /**
061         * Resolve the given destination name, convert the payload request Object
062         * to serialized form, possibly using a
063         * {@link org.springframework.messaging.converter.MessageConverter},
064         * wrap it as a message with the given headers and send it to the resolved destination,
065         * receive a reply and convert its body to the specified target class.
066         * @param destinationName the name of the target destination
067         * @param request the payload for the request message to send
068         * @param headers the headers for the request message to send
069         * @param targetClass the target class to convert the payload of the reply to
070         * @return the converted payload of the reply message, possibly {@code null} if
071         * the message could not be received, for example due to a timeout
072         */
073        <T> T convertSendAndReceive(String destinationName, Object request, Map<String, Object> headers,
074                        Class<T> targetClass) throws MessagingException;
075
076        /**
077         * Resolve the given destination name, convert the payload request Object
078         * to serialized form, possibly using a
079         * {@link org.springframework.messaging.converter.MessageConverter},
080         * wrap it as a message, apply the given post process, and send the resulting
081         * message to the resolved destination, then receive a reply and convert its
082         * body to the specified target class.
083         * @param destinationName the name of the target destination
084         * @param request the payload for the request message to send
085         * @param targetClass the target class to convert the payload of the reply to
086         * @param requestPostProcessor post process for the request message
087         * @return the converted payload of the reply message, possibly {@code null} if
088         * the message could not be received, for example due to a timeout
089         */
090        <T> T convertSendAndReceive(String destinationName, Object request,
091                        Class<T> targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException;
092
093        /**
094         * Resolve the given destination name, convert the payload request Object
095         * to serialized form, possibly using a
096         * {@link org.springframework.messaging.converter.MessageConverter},
097         * wrap it as a message with the given headers, apply the given post process,
098         * and send the resulting message to the resolved destination, then receive
099         * a reply and convert its body to the specified target class.
100         * @param destinationName the name of the target destination
101         * @param request the payload for the request message to send
102         * @param headers the headers for the request message to send
103         * @param targetClass the target class to convert the payload of the reply to
104         * @param requestPostProcessor post process for the request message
105         * @return the converted payload of the reply message, possibly {@code null} if
106         * the message could not be received, for example due to a timeout
107         */
108        <T> T convertSendAndReceive(String destinationName, Object request, Map<String, Object> headers,
109                        Class<T> targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException;
110
111}