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