Class AbstractMessageSendingTemplate<D>
java.lang.Object
org.springframework.messaging.core.AbstractMessageSendingTemplate<D>
- Type Parameters:
D
- the destination type
- All Implemented Interfaces:
MessageSendingOperations<D>
- Direct Known Subclasses:
AbstractMessageReceivingTemplate
,SimpMessagingTemplate
public abstract class AbstractMessageSendingTemplate<D>
extends Object
implements MessageSendingOperations<D>
Abstract base class for implementations of
MessageSendingOperations
.- Since:
- 4.0
- Author:
- Mark Fisher, Rossen Stoyanchev, Stephane Nicoll
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
convertAndSend
(D destination, Object payload) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message and send it to the given destination.void
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers and send it to the given destination.void
convertAndSend
(D destination, Object payload, Map<String, Object> headers, MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers, apply the given post-processor, and send the resulting message to the given destination.void
convertAndSend
(D destination, Object payload, MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post-processor, and send the resulting message to the given destination.void
convertAndSend
(Object payload) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message and send it to a default destination.void
convertAndSend
(Object payload, MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post-processor, and send the resulting message to a default destination.protected Message<?>
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers and apply the given post-processor.protected abstract void
Actually send the given message to the given destination.Return the configured default destination.Return the configuredMessageConverter
.protected final D
processHeadersToSend
(Map<String, Object> headers) Provides access to the map of input headers before a send operation.void
Send a message to the given destination.void
Send a message to a default destination.void
setDefaultDestination
(D defaultDestination) Configure the default destination to use in send methods that don't have a destination argument.void
setMessageConverter
(MessageConverter messageConverter) Set theMessageConverter
to use inconvertAndSend
methods.
-
Field Details
-
CONVERSION_HINT_HEADER
Name of the header that can be set to provide further information (for example, aMethodParameter
instance) about the origin of the payload, to be taken into account as a conversion hint.- Since:
- 4.2
- See Also:
-
logger
-
-
Constructor Details
-
AbstractMessageSendingTemplate
public AbstractMessageSendingTemplate()
-
-
Method Details
-
setDefaultDestination
Configure the default destination to use in send methods that don't have a destination argument. If a default destination is not configured, send methods without a destination argument will raise an exception if invoked. -
getDefaultDestination
Return the configured default destination. -
setMessageConverter
Set theMessageConverter
to use inconvertAndSend
methods.By default,
SimpleMessageConverter
is used.- Parameters:
messageConverter
- the message converter to use
-
getMessageConverter
Return the configuredMessageConverter
. -
send
Description copied from interface:MessageSendingOperations
Send a message to a default destination.- Specified by:
send
in interfaceMessageSendingOperations<D>
- Parameters:
message
- the message to send
-
getRequiredDefaultDestination
-
send
Description copied from interface:MessageSendingOperations
Send a message to the given destination.- Specified by:
send
in interfaceMessageSendingOperations<D>
- Parameters:
destination
- the target destinationmessage
- the message to send
-
convertAndSend
Description copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message and send it to a default destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<D>
- Parameters:
payload
- the Object to use as payload- Throws:
MessagingException
-
convertAndSend
Description copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message and send it to the given destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<D>
- Parameters:
destination
- the target destinationpayload
- the Object to use as payload- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(D destination, Object payload, @Nullable Map<String, Object> headers) throws MessagingExceptionDescription copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers and send it to the given destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<D>
- Parameters:
destination
- the target destinationpayload
- the Object to use as payloadheaders
- the headers for the message to send- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException Description copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post-processor, and send the resulting message to a default destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<D>
- Parameters:
payload
- the Object to use as payloadpostProcessor
- the post-processor to apply to the message- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(D destination, Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException Description copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message, apply the given post-processor, and send the resulting message to the given destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<D>
- Parameters:
destination
- the target destinationpayload
- the Object to use as payloadpostProcessor
- the post-processor to apply to the message- Throws:
MessagingException
-
convertAndSend
public void convertAndSend(D destination, Object payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingExceptionDescription copied from interface:MessageSendingOperations
Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers, apply the given post-processor, and send the resulting message to the given destination.- Specified by:
convertAndSend
in interfaceMessageSendingOperations<D>
- Parameters:
destination
- the target destinationpayload
- the Object to use as payloadheaders
- the headers for the message to sendpostProcessor
- the post-processor to apply to the message- Throws:
MessagingException
-
doConvert
protected Message<?> doConvert(Object payload, @Nullable Map<String, Object> headers, @Nullable MessagePostProcessor postProcessor) Convert the given Object to serialized form, possibly using aMessageConverter
, wrap it as a message with the given headers and apply the given post-processor.- Parameters:
payload
- the Object to use as payloadheaders
- the headers for the message to sendpostProcessor
- the post-processor to apply to the message- Returns:
- the converted message
-
processHeadersToSend
Provides access to the map of input headers before a send operation. Subclasses can modify the headers and then return the same or a different map.This default implementation in this class returns the input map.
- Parameters:
headers
- the headers to send (ornull
if none)- Returns:
- the actual headers to send (or
null
if none)
-
doSend
Actually send the given message to the given destination.- Parameters:
destination
- the target destinationmessage
- the message to send
-