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 a destination.
027 *
028 * @author Mark Fisher
029 * @author Rossen Stoyanchev
030 * @since 4.0
031 * @param <D> the destination type
032 */
033public interface MessageSendingOperations<D> {
034
035        /**
036         * Send a message to a default destination.
037         * @param message the message to send
038         */
039        void send(Message<?> message) throws MessagingException;
040
041        /**
042         * Send a message to the given destination.
043         * @param destination the target destination
044         * @param message the message to send
045         */
046        void send(D destination, Message<?> message) throws MessagingException;
047
048        /**
049         * Convert the given Object to serialized form, possibly using a
050         * {@link org.springframework.messaging.converter.MessageConverter},
051         * wrap it as a message and send it to a default destination.
052         * @param payload the Object to use as payload
053         */
054        void convertAndSend(Object payload) throws MessagingException;
055
056        /**
057         * Convert the given Object to serialized form, possibly using a
058         * {@link org.springframework.messaging.converter.MessageConverter},
059         * wrap it as a message and send it to the given destination.
060         * @param destination the target destination
061         * @param payload the Object to use as payload
062         */
063        void convertAndSend(D destination, Object payload) throws MessagingException;
064
065        /**
066         * Convert the given Object 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
069         * the given destination.
070         * @param destination the target destination
071         * @param payload the Object to use as payload
072         * @param headers the headers for the message to send
073         */
074        void convertAndSend(D destination, Object payload, Map<String, Object> headers) throws MessagingException;
075
076        /**
077         * Convert the given Object to serialized form, possibly using a
078         * {@link org.springframework.messaging.converter.MessageConverter},
079         * wrap it as a message, apply the given post processor, and send
080         * the resulting message to a default destination.
081         * @param payload the Object to use as payload
082         * @param postProcessor the post processor to apply to the message
083         */
084        void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException;
085
086        /**
087         * Convert the given Object to serialized form, possibly using a
088         * {@link org.springframework.messaging.converter.MessageConverter},
089         * wrap it as a message, apply the given post processor, and send
090         * the resulting message to the given destination.
091         * @param destination the target destination
092         * @param payload the Object to use as payload
093         * @param postProcessor the post processor to apply to the message
094         */
095        void convertAndSend(D destination, Object payload, MessagePostProcessor postProcessor) throws MessagingException;
096
097        /**
098         * Convert the given Object to serialized form, possibly using a
099         * {@link org.springframework.messaging.converter.MessageConverter},
100         * wrap it as a message with the given headers, apply the given post processor,
101         * and send the resulting message to the given destination.
102         * @param destination the target destination
103         * @param payload the Object to use as payload
104         * @param headers the headers for the message to send
105         * @param postProcessor the post processor to apply to the message
106         */
107        void convertAndSend(D destination, Object payload, @Nullable Map<String, Object> headers,
108                        @Nullable MessagePostProcessor postProcessor) throws MessagingException;
109
110}