Top Description Inners Fields Constructors Methods
org.springframework.messaging.core

public Class GenericMessagingTemplate

extends AbstractDestinationResolvingMessagingTemplate<MessageChannel>
implements BeanFactoryAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware
Imports
java.util.concurrent.CountDownLatch, .TimeUnit, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, org.springframework.lang.Nullable, org.springframework.messaging.Message, .MessageChannel, .MessageDeliveryException, .MessageHeaders, .PollableChannel, org.springframework.messaging.support.MessageBuilder, .MessageHeaderAccessor, org.springframework.util.Assert

A messaging template that resolves destinations names to MessageChannel's to send and receive messages from.
Authors
Mark Fisher, Rossen Stoyanchev, Gary Russell
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
GenericMessagingTemplate.TemporaryReplyChannel

A temporary channel for receiving a single reply message.

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_RECEIVE_TIMEOUT_HEADER

The default header key used for a receive timeout.

public static final String
DEFAULT_SEND_TIMEOUT_HEADER

The default header key used for a send timeout.

private volatile long
private String
private volatile long
private String
private volatile boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final Message<?>
doReceive(MessageChannel
the target destination
channel
)

Implements abstract org.springframework.messaging.core.AbstractMessageReceivingTemplate.doReceive.

Actually receive a message from the given destination.
protected final Message<?>
doReceive(MessageChannel channel, long timeout)

protected final void
protected final void
doSend(MessageChannel channel, Message<?> message, long timeout)

protected final Message<?>
public long
getReceiveTimeout()

Return the configured receive operation timeout value.

public String
getReceiveTimeoutHeader()

Return the configured receive-timeout header.

public long
getSendTimeout()

Return the configured default send operation timeout value.

public String
getSendTimeoutHeader()

Return the configured send-timeout header.

private Long
headerToLong(Object headerValue)

private long
receiveTimeout(Message<?> requestMessage)

private long
sendTimeout(Message<?> requestMessage)

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.
public void
setReceiveTimeout(long
the receive timeout in milliseconds
receiveTimeout
)

Configure the default timeout value to use for receive operations.

public void
setReceiveTimeoutHeader(String receiveTimeoutHeader)

Set the name of the header used to determine the send timeout (if present).

public void
setSendTimeout(long
the send timeout in milliseconds
sendTimeout
)

Configure the default timeout value to use for send operations.

public void
setSendTimeoutHeader(String sendTimeoutHeader)

Set the name of the header used to determine the send timeout (if present).

public void
setThrowExceptionOnLateReply(boolean
whether to throw an exception or not
throwExceptionOnLateReply
)

Whether the thread sending a reply should have an exception raised if the receiving thread isn't going to receive the reply either because it timed out, or because it already received a reply, or because it got an exception while sending the request message.

Inherited from org.springframework.messaging.core.AbstractDestinationResolvingMessagingTemplate:
convertAndSendconvertAndSendconvertAndSendconvertAndSendconvertSendAndReceiveconvertSendAndReceiveconvertSendAndReceiveconvertSendAndReceivegetDestinationResolverreceivereceiveAndConvertresolveDestinationsendsendAndReceivesetDestinationResolver

Field Detail

DEFAULT_RECEIVE_TIMEOUT_HEADERback to summary
public static final String DEFAULT_RECEIVE_TIMEOUT_HEADER

The default header key used for a receive timeout.

DEFAULT_SEND_TIMEOUT_HEADERback to summary
public static final String DEFAULT_SEND_TIMEOUT_HEADER

The default header key used for a send timeout.

receiveTimeoutback to summary
private volatile long receiveTimeout
receiveTimeoutHeaderback to summary
private String receiveTimeoutHeader
sendTimeoutback to summary
private volatile long sendTimeout
sendTimeoutHeaderback to summary
private String sendTimeoutHeader
throwExceptionOnLateReplyback to summary
private volatile boolean throwExceptionOnLateReply

Constructor Detail

GenericMessagingTemplateback to summary
public GenericMessagingTemplate()

Method Detail

doReceiveback to summary
protected final Message<?> doReceive(MessageChannel channel)

Implements abstract org.springframework.messaging.core.AbstractMessageReceivingTemplate.doReceive.

Doc from org.springframework.messaging.core.AbstractMessageReceivingTemplate.doReceive.

Actually receive a message from the given destination.

Parameters
channel:MessageChannel

the target destination

Returns:Message<?>

the received message, possibly null if the message could not be received, for example due to a timeout

Annotations
@Override
@Nullable
doReceiveback to summary
protected final Message<?> doReceive(MessageChannel channel, long timeout)
Annotations
@Nullable
doSendback to summary
protected final void doSend(MessageChannel channel, Message<?> message)

Implements abstract org.springframework.messaging.core.AbstractMessageSendingTemplate.doSend.

Annotations
@Override
doSendback to summary
protected final void doSend(MessageChannel channel, Message<?> message, long timeout)
doSendAndReceiveback to summary
protected final Message<?> doSendAndReceive(MessageChannel channel, Message<?> requestMessage)

Implements abstract org.springframework.messaging.core.AbstractMessagingTemplate.doSendAndReceive.

Annotations
@Override
@Nullable
getReceiveTimeoutback to summary
public long getReceiveTimeout()

Return the configured receive operation timeout value.

getReceiveTimeoutHeaderback to summary
public String getReceiveTimeoutHeader()

Return the configured receive-timeout header.

Since
5.0
getSendTimeoutback to summary
public long getSendTimeout()

Return the configured default send operation timeout value.

getSendTimeoutHeaderback to summary
public String getSendTimeoutHeader()

Return the configured send-timeout header.

Since
5.0
headerToLongback to summary
private Long headerToLong(Object headerValue)
Annotations
@Nullable
receiveTimeoutback to summary
private long receiveTimeout(Message<?> requestMessage)
sendTimeoutback to summary
private long sendTimeout(Message<?> requestMessage)
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory) throws BeansException

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Invoked after the population of normal bean properties but before an initialization callback such as InitializingBean#afterPropertiesSet() or a custom init-method.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
Exceptions
BeansException:
in case of initialization errors
setReceiveTimeoutback to summary
public void setReceiveTimeout(long receiveTimeout)

Configure the default timeout value to use for receive operations. May be overridden for individual messages when using sendAndReceive operations.

Parameters
receiveTimeout:long

the receive timeout in milliseconds

See Also
setReceiveTimeoutHeader(String)
setReceiveTimeoutHeaderback to summary
public void setReceiveTimeoutHeader(String receiveTimeoutHeader)

Set the name of the header used to determine the send timeout (if present). Default receiveTimeout. The header is removed before sending the message to avoid propagation.

Since
5.0
setSendTimeoutback to summary
public void setSendTimeout(long sendTimeout)

Configure the default timeout value to use for send operations. May be overridden for individual messages.

Parameters
sendTimeout:long

the send timeout in milliseconds

See Also
setSendTimeoutHeader(String)
setSendTimeoutHeaderback to summary
public void setSendTimeoutHeader(String sendTimeoutHeader)

Set the name of the header used to determine the send timeout (if present). Default sendTimeout.

The header is removed before sending the message to avoid propagation.

Since
5.0
setThrowExceptionOnLateReplyback to summary
public void setThrowExceptionOnLateReply(boolean throwExceptionOnLateReply)

Whether the thread sending a reply should have an exception raised if the receiving thread isn't going to receive the reply either because it timed out, or because it already received a reply, or because it got an exception while sending the request message.

The default value is false in which case only a WARN message is logged. If set to true a MessageDeliveryException is raised in addition to the log message.

Parameters
throwExceptionOnLateReply:boolean

whether to throw an exception or not

org.springframework.messaging.core back to summary

private final Class GenericMessagingTemplate.TemporaryReplyChannel

extends Object
implements PollableChannel
Class Inheritance
  • java.lang.Object
  • org.springframework.messaging.core.GenericMessagingTemplate.TemporaryReplyChannel
All Implemented Interfaces
org.springframework.messaging.PollableChannel, org.springframework.messaging.MessageChannel

A temporary channel for receiving a single reply message.

Field Summary

Modifier and TypeField and Description
private volatile boolean
private volatile boolean
private volatile boolean
private final Log
private final CountDownLatch
private volatile Message<?>
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
TemporaryReplyChannel(boolean throwExceptionOnLateReply)

Method Summary

Modifier and TypeMethod and Description
public Message<?>
receive()

Implements org.springframework.messaging.PollableChannel.receive.

Receive a message from this channel, blocking indefinitely if necessary.
public Message<?>
receive(long
the timeout in milliseconds or MessageChannel#INDEFINITE_TIMEOUT.
timeout
)

Implements org.springframework.messaging.PollableChannel.receive.

Receive a message from this channel, blocking until either a message is available or the specified timeout period elapses.
public boolean
send(Message<?>
the message to send
message
)

Overrides default org.springframework.messaging.MessageChannel.send.

Send a Message to this channel.
public boolean
send(Message<?>
the message to send
message
,
long
the timeout in milliseconds or INDEFINITE_TIMEOUT
timeout
)

Implements org.springframework.messaging.MessageChannel.send.

Send a message, blocking until either the message is accepted or the specified timeout period elapses.
public void
setSendFailed(boolean hasSendError)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

hasReceivedback to summary
private volatile boolean hasReceived
hasSendFailedback to summary
private volatile boolean hasSendFailed
hasTimedOutback to summary
private volatile boolean hasTimedOut
loggerback to summary
private final Log logger
replyLatchback to summary
private final CountDownLatch replyLatch
replyMessageback to summary
private volatile Message<?> replyMessage
Annotations
@Nullable
throwExceptionOnLateReplyback to summary
private final boolean throwExceptionOnLateReply

Constructor Detail

TemporaryReplyChannelback to summary
pack-priv TemporaryReplyChannel(boolean throwExceptionOnLateReply)

Method Detail

receiveback to summary
public Message<?> receive()

Implements org.springframework.messaging.PollableChannel.receive.

Doc from org.springframework.messaging.PollableChannel.receive.

Receive a message from this channel, blocking indefinitely if necessary.

Returns:Message<?>

the next available Message or null if interrupted

Annotations
@Override
@Nullable
receiveback to summary
public Message<?> receive(long timeout)

Implements org.springframework.messaging.PollableChannel.receive.

Doc from org.springframework.messaging.PollableChannel.receive.

Receive a message from this channel, blocking until either a message is available or the specified timeout period elapses.

Parameters
timeout:long

the timeout in milliseconds or MessageChannel#INDEFINITE_TIMEOUT.

Returns:Message<?>

the next available Message or null if the specified timeout period elapses or the message reception is interrupted

Annotations
@Override
@Nullable
sendback to summary
public boolean send(Message<?> message)

Overrides default org.springframework.messaging.MessageChannel.send.

Doc from org.springframework.messaging.MessageChannel.send.

Send a Message to this channel. If the message is sent successfully, the method returns true. If the message cannot be sent due to a non-fatal reason, the method returns false. The method may also throw a RuntimeException in case of non-recoverable errors.

This method may block indefinitely, depending on the implementation. To provide a maximum wait time, use send(Message, long).

Parameters
message:Message<?>

the message to send

Returns:boolean

whether the message was sent

Annotations
@Override
sendback to summary
public boolean send(Message<?> message, long timeout)

Implements org.springframework.messaging.MessageChannel.send.

Doc from org.springframework.messaging.MessageChannel.send.

Send a message, blocking until either the message is accepted or the specified timeout period elapses.

Parameters
message:Message<?>

the message to send

timeout:long

the timeout in milliseconds or INDEFINITE_TIMEOUT

Returns:boolean

true if the message is sent, false if not including a timeout of an interrupt of the send

Annotations
@Override
setSendFailedback to summary
public void setSendFailed(boolean hasSendError)