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