public class RabbitMessagingTemplate extends AbstractMessagingTemplate<String> implements RabbitMessageOperations, InitializingBean
RabbitMessageOperations.CONVERSION_HINT_HEADER, logger| Constructor and Description |
|---|
RabbitMessagingTemplate()
Constructor for use with bean properties.
|
RabbitMessagingTemplate(RabbitTemplate rabbitTemplate)
Create an instance with the
RabbitTemplate to use. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected MessagingException |
convertAmqpException(RuntimeException ex) |
protected Message<?> |
convertAmqpMessage(Message message) |
void |
convertAndSend(String exchange,
String routingKey,
Object payload)
Convert the given Object to serialized form, possibly using a
MessageConverter,
wrap it as a message and send it to a specific exchange with a
specific routing key. |
void |
convertAndSend(String exchange,
String routingKey,
Object payload,
Map<String,Object> headers)
Convert the given Object to serialized form, possibly using a
MessageConverter,
wrap it as a message with the given headers and send it to a
specific exchange with a specific routing key. |
void |
convertAndSend(String exchange,
String routingKey,
Object payload,
Map<String,Object> headers,
MessagePostProcessor postProcessor)
Convert the given Object to serialized form, possibly using a
MessageConverter,
wrap it as a message with the given headers, apply the given post processor,
and send the resulting message to a specific exchange with a specific
routing key. |
void |
convertAndSend(String exchange,
String routingKey,
Object payload,
MessagePostProcessor postProcessor)
Convert the given Object to serialized form, possibly using a
MessageConverter,
wrap it as a message, apply the given post processor, and send
the resulting message to a specific exchange with a specific
routing key. |
<T> T |
convertSendAndReceive(String exchange,
String routingKey,
Object request,
Class<T> targetClass)
Convert the given request Object to serialized form, possibly using a
MessageConverter, send
it as a Message to a specific exchange with a specific routing key,
receive the reply and convert its body of the specified target class. |
<T> T |
convertSendAndReceive(String exchange,
String routingKey,
Object request,
Class<T> targetClass,
MessagePostProcessor requestPostProcessor)
Convert the given request Object to serialized form, possibly using a
MessageConverter,
apply the given post processor and send the resulting Message to
a specific exchange with a specific routing key, receive the reply and
convert its body of the given target class. |
<T> T |
convertSendAndReceive(String exchange,
String routingKey,
Object request,
Map<String,Object> headers,
Class<T> targetClass)
Convert the given request Object to serialized form, possibly using a
MessageConverter, send
it as a Message with the given headers, to a specific exchange
with a specific routing key, receive the reply and convert its body of
the specified target class. |
<T> T |
convertSendAndReceive(String exchange,
String routingKey,
Object request,
Map<String,Object> headers,
Class<T> targetClass,
MessagePostProcessor requestPostProcessor)
Convert the given request Object to serialized form, possibly using a
MessageConverter,
wrap it as a message with the given headers, apply the given post processor
and send the resulting Message to a specific exchange with a
specific routing key,, receive the reply and convert its body of the
given target class. |
protected Message<?> |
doReceive(String destination) |
protected void |
doSend(String destination,
Message<?> message) |
protected void |
doSend(String exchange,
String routingKey,
Message<?> message) |
protected Message<?> |
doSendAndReceive(String destination,
Message<?> requestMessage) |
protected Message<?> |
doSendAndReceive(String exchange,
String routingKey,
Message<?> requestMessage) |
MessageConverter |
getAmqpMessageConverter() |
RabbitTemplate |
getRabbitTemplate() |
Message<?> |
receive() |
<T> T |
receiveAndConvert(Class<T> targetClass) |
void |
send(String exchange,
String routingKey,
Message<?> message)
Send a message to a specific exchange with a specific routing key.
|
Message<?> |
sendAndReceive(String exchange,
String routingKey,
Message<?> requestMessage)
Send a request message to a specific exchange with a specific routing key and
wait for the reply.
|
void |
setAmqpMessageConverter(MessageConverter amqpMessageConverter)
|
void |
setRabbitTemplate(RabbitTemplate rabbitTemplate)
Set the
RabbitTemplate to use. |
void |
setUseTemplateDefaultReceiveQueue(boolean useTemplateDefaultReceiveQueue)
When true, use the underlying
RabbitTemplate's defaultReceiveQueue property
(if configured) for receive only methods instead of the defaultDestination
configured in this template. |
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceivedoConvert, receive, receiveAndConvertconvertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, send, setDefaultDestination, setMessageConverterclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconvertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send, sendreceive, receiveAndConvertconvertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceivepublic RabbitMessagingTemplate()
setRabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) to be called.public RabbitMessagingTemplate(RabbitTemplate rabbitTemplate)
RabbitTemplate to use.rabbitTemplate - the template.public void setRabbitTemplate(RabbitTemplate rabbitTemplate)
RabbitTemplate to use.rabbitTemplate - the template.public RabbitTemplate getRabbitTemplate()
RabbitTemplate.public void setAmqpMessageConverter(MessageConverter amqpMessageConverter)
MessageConverter to use to convert a Message from
the messaging to and from a Message.
By default, a MessagingMessageConverter is defined using the provided
RabbitTemplate's message converter (a
SimpleMessageConverter
by default) to convert the payload of the message.
Consider configuring a MessagingMessageConverter with a different
payload converter
for more advanced scenarios.
amqpMessageConverter - the message converter.MessagingMessageConverterpublic MessageConverter getAmqpMessageConverter()
MessageConverter to use to convert a Message
from the messaging to and from a Message.public void setUseTemplateDefaultReceiveQueue(boolean useTemplateDefaultReceiveQueue)
RabbitTemplate's defaultReceiveQueue property
(if configured) for receive only methods instead of the defaultDestination
configured in this template. Set this to true to use the template's queue instead.
Default false, but will be true in a future release.useTemplateDefaultReceiveQueue - true to use the template's queue.public void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanpublic void send(String exchange, String routingKey, Message<?> message) throws MessagingException
RabbitMessageOperationssend in interface RabbitMessageOperationsexchange - the name of the exchangeroutingKey - the routing keymessage - the message to sendMessagingException - a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload) throws MessagingException
RabbitMessageOperationsMessageConverter,
wrap it as a message and send it to a specific exchange with a
specific routing key.convertAndSend in interface RabbitMessageOperationsexchange - the name of the exchangeroutingKey - the routing keypayload - the Object to use as payloadMessagingException - a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload, @Nullable Map<String,Object> headers) throws MessagingException
RabbitMessageOperationsMessageConverter,
wrap it as a message with the given headers and send it to a
specific exchange with a specific routing key.convertAndSend in interface RabbitMessageOperationsexchange - the name of the exchangeroutingKey - the routing keypayload - the Object to use as payloadheaders - headers for the message to sendMessagingException - a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload, @Nullable MessagePostProcessor postProcessor) throws MessagingException
RabbitMessageOperationsMessageConverter,
wrap it as a message, apply the given post processor, and send
the resulting message to a specific exchange with a specific
routing key.convertAndSend in interface RabbitMessageOperationsexchange - the name of the exchangeroutingKey - the routing keypayload - the Object to use as payloadpostProcessor - the post processor to apply to the messageMessagingException - a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload, @Nullable Map<String,Object> headers, @Nullable MessagePostProcessor postProcessor) throws MessagingException
RabbitMessageOperationsMessageConverter,
wrap it as a message with the given headers, apply the given post processor,
and send the resulting message to a specific exchange with a specific
routing key.convertAndSend in interface RabbitMessageOperationsexchange - the name of the exchangeroutingKey - the routing keypayload - the Object to use as payloadheaders - headers for the message to sendpostProcessor - the post processor to apply to the messageMessagingException - a messaging exception.@Nullable public Message<?> sendAndReceive(String exchange, String routingKey, Message<?> requestMessage) throws MessagingException
RabbitMessageOperationssendAndReceive in interface RabbitMessageOperationsexchange - the name of the exchangeroutingKey - the routing keyrequestMessage - the message to sendnull if the message could not be received,
for example due to a timeoutMessagingException - a messaging exception.@Nullable public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, Class<T> targetClass) throws MessagingException
RabbitMessageOperationsMessageConverter, send
it as a Message to a specific exchange with a specific routing key,
receive the reply and convert its body of the specified target class.convertSendAndReceive in interface RabbitMessageOperationsT - return typeexchange - the name of the exchangeroutingKey - the routing keyrequest - payload for the request message to sendtargetClass - the target type to convert the payload of the reply tonull if the message
could not be received, for example due to a timeoutMessagingException - a messaging exception.@Nullable public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, @Nullable Map<String,Object> headers, Class<T> targetClass) throws MessagingException
RabbitMessageOperationsMessageConverter, send
it as a Message with the given headers, to a specific exchange
with a specific routing key, receive the reply and convert its body of
the specified target class.convertSendAndReceive in interface RabbitMessageOperationsT - return typeexchange - the name of the exchangeroutingKey - the routing keyrequest - payload for the request message to sendheaders - headers for the request message to sendtargetClass - the target type to convert the payload of the reply tonull if the message
could not be received, for example due to a timeoutMessagingException - a messaging exception.@Nullable public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException
RabbitMessageOperationsMessageConverter,
apply the given post processor and send the resulting Message to
a specific exchange with a specific routing key, receive the reply and
convert its body of the given target class.convertSendAndReceive in interface RabbitMessageOperationsT - return typeexchange - the name of the exchangeroutingKey - the routing keyrequest - payload for the request message to sendtargetClass - the target type to convert the payload of the reply torequestPostProcessor - post process to apply to the request messagenull if the message
could not be received, for example due to a timeoutMessagingException - a messaging exception.@Nullable public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, @Nullable Map<String,Object> headers, Class<T> targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException
RabbitMessageOperationsMessageConverter,
wrap it as a message with the given headers, apply the given post processor
and send the resulting Message to a specific exchange with a
specific routing key,, receive the reply and convert its body of the
given target class.convertSendAndReceive in interface RabbitMessageOperationsT - return typeexchange - the name of the exchangeroutingKey - the routing keyrequest - payload for the request message to sendheaders - headers for the message to sendtargetClass - the target type to convert the payload of the reply torequestPostProcessor - post process to apply to the request messagenull if the message
could not be received, for example due to a timeoutMessagingException - a messaging exception.protected void doSend(String destination, Message<?> message)
doSend in class AbstractMessageSendingTemplate<String>@Nullable public Message<?> receive()
receive in interface MessageReceivingOperations<String>receive in class AbstractMessageReceivingTemplate<String>@Nullable public <T> T receiveAndConvert(Class<T> targetClass)
receiveAndConvert in interface MessageReceivingOperations<String>receiveAndConvert in class AbstractMessageReceivingTemplate<String>protected Message<?> doReceive(String destination)
doReceive in class AbstractMessageReceivingTemplate<String>@Nullable protected Message<?> doSendAndReceive(String destination, Message<?> requestMessage)
doSendAndReceive in class AbstractMessagingTemplate<String>@Nullable protected Message<?> doSendAndReceive(String exchange, String routingKey, Message<?> requestMessage)
protected MessagingException convertAmqpException(RuntimeException ex)