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