public class RabbitMessagingTemplate extends org.springframework.messaging.core.AbstractMessagingTemplate<String> implements RabbitMessageOperations, org.springframework.beans.factory.InitializingBean
RabbitMessageOperations
.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 org.springframework.messaging.MessagingException |
convertAmqpException(RuntimeException ex) |
protected org.springframework.messaging.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,
org.springframework.messaging.core.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,
org.springframework.messaging.core.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,
org.springframework.messaging.core.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,
org.springframework.messaging.core.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 org.springframework.messaging.Message<?> |
doReceive(String destination) |
protected void |
doSend(String destination,
org.springframework.messaging.Message<?> message) |
protected void |
doSend(String exchange,
String routingKey,
org.springframework.messaging.Message<?> message) |
protected org.springframework.messaging.Message<?> |
doSendAndReceive(String destination,
org.springframework.messaging.Message<?> requestMessage) |
protected org.springframework.messaging.Message<?> |
doSendAndReceive(String exchange,
String routingKey,
org.springframework.messaging.Message<?> requestMessage) |
MessageConverter |
getAmqpMessageConverter() |
RabbitTemplate |
getRabbitTemplate() |
void |
send(String exchange,
String routingKey,
org.springframework.messaging.Message<?> message)
Send a message to a specific exchange with a specific routing key.
|
org.springframework.messaging.Message<?> |
sendAndReceive(String exchange,
String routingKey,
org.springframework.messaging.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. |
convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, convertSendAndReceive, sendAndReceive, sendAndReceive
doConvert, receive, receive, receiveAndConvert, receiveAndConvert
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, doConvert, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, send, setDefaultDestination, setMessageConverter
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, send, send
public 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.MessagingMessageConverter
public MessageConverter getAmqpMessageConverter()
MessageConverter
to use to convert a Message
from the messaging to and from a Message
.public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
public void send(String exchange, String routingKey, org.springframework.messaging.Message<?> message) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
send
in interface RabbitMessageOperations
exchange
- the name of the exchangeroutingKey
- the routing keymessage
- the message to sendorg.springframework.messaging.MessagingException
- a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
MessageConverter
,
wrap it as a message and send it to a specific exchange with a
specific routing key.convertAndSend
in interface RabbitMessageOperations
exchange
- the name of the exchangeroutingKey
- the routing keypayload
- the Object to use as payloadorg.springframework.messaging.MessagingException
- a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload, Map<String,Object> headers) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
MessageConverter
,
wrap it as a message with the given headers and send it to a
specific exchange with a specific routing key.convertAndSend
in interface RabbitMessageOperations
exchange
- the name of the exchangeroutingKey
- the routing keypayload
- the Object to use as payloadheaders
- headers for the message to sendorg.springframework.messaging.MessagingException
- a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload, org.springframework.messaging.core.MessagePostProcessor postProcessor) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
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.convertAndSend
in interface RabbitMessageOperations
exchange
- the name of the exchangeroutingKey
- the routing keypayload
- the Object to use as payloadpostProcessor
- the post processor to apply to the messageorg.springframework.messaging.MessagingException
- a messaging exception.public void convertAndSend(String exchange, String routingKey, Object payload, Map<String,Object> headers, org.springframework.messaging.core.MessagePostProcessor postProcessor) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
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.convertAndSend
in interface RabbitMessageOperations
exchange
- 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 messageorg.springframework.messaging.MessagingException
- a messaging exception.public org.springframework.messaging.Message<?> sendAndReceive(String exchange, String routingKey, org.springframework.messaging.Message<?> requestMessage) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
sendAndReceive
in interface RabbitMessageOperations
exchange
- the name of the exchangeroutingKey
- the routing keyrequestMessage
- the message to sendnull
if the message could not be received,
for example due to a timeoutorg.springframework.messaging.MessagingException
- a messaging exception.public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, Class<T> targetClass) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
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.convertSendAndReceive
in interface RabbitMessageOperations
T
- 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 timeoutorg.springframework.messaging.MessagingException
- a messaging exception.public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, Map<String,Object> headers, Class<T> targetClass) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
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.convertSendAndReceive
in interface RabbitMessageOperations
T
- 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 timeoutorg.springframework.messaging.MessagingException
- a messaging exception.public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, Class<T> targetClass, org.springframework.messaging.core.MessagePostProcessor requestPostProcessor) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
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.convertSendAndReceive
in interface RabbitMessageOperations
T
- 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 timeoutorg.springframework.messaging.MessagingException
- a messaging exception.public <T> T convertSendAndReceive(String exchange, String routingKey, Object request, Map<String,Object> headers, Class<T> targetClass, org.springframework.messaging.core.MessagePostProcessor requestPostProcessor) throws org.springframework.messaging.MessagingException
RabbitMessageOperations
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.convertSendAndReceive
in interface RabbitMessageOperations
T
- 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 timeoutorg.springframework.messaging.MessagingException
- a messaging exception.protected void doSend(String destination, org.springframework.messaging.Message<?> message)
doSend
in class org.springframework.messaging.core.AbstractMessageSendingTemplate<String>
protected void doSend(String exchange, String routingKey, org.springframework.messaging.Message<?> message)
protected org.springframework.messaging.Message<?> doReceive(String destination)
doReceive
in class org.springframework.messaging.core.AbstractMessageReceivingTemplate<String>
protected org.springframework.messaging.Message<?> doSendAndReceive(String destination, org.springframework.messaging.Message<?> requestMessage)
doSendAndReceive
in class org.springframework.messaging.core.AbstractMessagingTemplate<String>
protected org.springframework.messaging.Message<?> doSendAndReceive(String exchange, String routingKey, org.springframework.messaging.Message<?> requestMessage)
protected org.springframework.messaging.Message<?> convertAmqpMessage(Message message)
protected org.springframework.messaging.MessagingException convertAmqpException(RuntimeException ex)