public class RocketMQTemplate extends org.springframework.messaging.core.AbstractMessageSendingTemplate<String> implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
| 构造器和说明 |
|---|
RocketMQTemplate() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
afterPropertiesSet() |
void |
asyncSend(String destination,
org.springframework.messaging.Message<?> message,
org.apache.rocketmq.client.producer.SendCallback sendCallback)
Send message to broker asynchronously. asynchronous transmission is generally used in response time sensitive
business scenarios.
|
void |
asyncSend(String destination,
org.springframework.messaging.Message<?> message,
org.apache.rocketmq.client.producer.SendCallback sendCallback,
long timeout)
Same to
asyncSend(String, Message, SendCallback) with send timeout specified in addition. |
void |
asyncSend(String destination,
org.springframework.messaging.Message<?> message,
org.apache.rocketmq.client.producer.SendCallback sendCallback,
long timeout,
int delayLevel)
Same to
asyncSend(String, Message, SendCallback) with send timeout and delay level specified in addition. |
void |
asyncSend(String destination,
Object payload,
org.apache.rocketmq.client.producer.SendCallback sendCallback)
|
void |
asyncSend(String destination,
Object payload,
org.apache.rocketmq.client.producer.SendCallback sendCallback,
long timeout)
Same to
asyncSend(String, Object, SendCallback) with send timeout specified in addition. |
void |
asyncSendOrderly(String destination,
org.springframework.messaging.Message<?> message,
String hashKey,
org.apache.rocketmq.client.producer.SendCallback sendCallback)
Same to
asyncSend(String, Message, SendCallback) with send orderly with hashKey by specified. |
void |
asyncSendOrderly(String destination,
org.springframework.messaging.Message<?> message,
String hashKey,
org.apache.rocketmq.client.producer.SendCallback sendCallback,
long timeout)
Same to
asyncSendOrderly(String, Message, String, SendCallback) with send timeout specified in
addition. |
void |
asyncSendOrderly(String destination,
Object payload,
String hashKey,
org.apache.rocketmq.client.producer.SendCallback sendCallback)
|
void |
asyncSendOrderly(String destination,
Object payload,
String hashKey,
org.apache.rocketmq.client.producer.SendCallback sendCallback,
long timeout)
Same to
asyncSendOrderly(String, Object, String, SendCallback) with send timeout specified in addition. |
boolean |
createAndStartTransactionMQProducer(String txProducerGroup,
RocketMQLocalTransactionListener transactionListener,
ExecutorService executorService,
org.apache.rocketmq.remoting.RPCHook rpcHook)
Create and start a transaction MQProducer, this new producer is cached in memory.
|
void |
destroy() |
protected org.springframework.messaging.Message<?> |
doConvert(Object payload,
Map<String,Object> headers,
org.springframework.messaging.core.MessagePostProcessor postProcessor) |
protected void |
doSend(String destination,
org.springframework.messaging.Message<?> message) |
String |
getCharset() |
org.apache.rocketmq.client.producer.MessageQueueSelector |
getMessageQueueSelector() |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
org.apache.rocketmq.client.producer.DefaultMQProducer |
getProducer() |
void |
removeTransactionMQProducer(String txProducerGroup)
Remove a TransactionMQProducer from cache by manual.
|
org.apache.rocketmq.client.producer.TransactionSendResult |
sendMessageInTransaction(String txProducerGroup,
String destination,
org.springframework.messaging.Message<?> message,
Object arg)
Send Spring Message in Transaction
|
void |
sendOneWay(String destination,
org.springframework.messaging.Message<?> message)
Similar to UDP, this method won't wait for
acknowledgement from broker before return.
|
void |
sendOneWay(String destination,
Object payload)
Same to
sendOneWay(String, Message) |
void |
sendOneWayOrderly(String destination,
org.springframework.messaging.Message<?> message,
String hashKey)
Same to
sendOneWay(String, Message) with send orderly with hashKey by specified. |
void |
sendOneWayOrderly(String destination,
Object payload,
String hashKey)
|
void |
setCharset(String charset) |
void |
setMessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector messageQueueSelector) |
void |
setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
void |
setProducer(org.apache.rocketmq.client.producer.DefaultMQProducer producer) |
org.apache.rocketmq.client.producer.SendResult |
syncSend(String destination,
Collection<org.springframework.messaging.Message<?>> messages,
long timeout)
syncSend batch messages in a given timeout.
|
org.apache.rocketmq.client.producer.SendResult |
syncSend(String destination,
org.springframework.messaging.Message<?> message)
Send message in synchronous mode.
|
org.apache.rocketmq.client.producer.SendResult |
syncSend(String destination,
org.springframework.messaging.Message<?> message,
long timeout)
Same to
syncSend(String, Message) with send timeout specified in addition. |
org.apache.rocketmq.client.producer.SendResult |
syncSend(String destination,
org.springframework.messaging.Message<?> message,
long timeout,
int delayLevel)
Same to
syncSend(String, Message) with send timeout specified in addition. |
org.apache.rocketmq.client.producer.SendResult |
syncSend(String destination,
Object payload)
Same to
syncSend(String, Message). |
org.apache.rocketmq.client.producer.SendResult |
syncSend(String destination,
Object payload,
long timeout)
Same to
syncSend(String, Object) with send timeout specified in addition. |
org.apache.rocketmq.client.producer.SendResult |
syncSendOrderly(String destination,
org.springframework.messaging.Message<?> message,
String hashKey)
Same to
syncSend(String, Message) with send orderly with hashKey by specified. |
org.apache.rocketmq.client.producer.SendResult |
syncSendOrderly(String destination,
org.springframework.messaging.Message<?> message,
String hashKey,
long timeout)
Same to
syncSendOrderly(String, Message, String) with send timeout specified in addition. |
org.apache.rocketmq.client.producer.SendResult |
syncSendOrderly(String destination,
Object payload,
String hashKey)
Same to
syncSend(String, Object) with send orderly with hashKey by specified. |
org.apache.rocketmq.client.producer.SendResult |
syncSendOrderly(String destination,
Object payload,
String hashKey,
long timeout)
Same to
syncSendOrderly(String, Object, String) with send timeout specified in addition. |
convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, convertAndSend, getDefaultDestination, getMessageConverter, getRequiredDefaultDestination, processHeadersToSend, send, send, setDefaultDestination, setMessageConverterpublic org.apache.rocketmq.client.producer.DefaultMQProducer getProducer()
public void setProducer(org.apache.rocketmq.client.producer.DefaultMQProducer producer)
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
public String getCharset()
public void setCharset(String charset)
public org.apache.rocketmq.client.producer.MessageQueueSelector getMessageQueueSelector()
public void setMessageQueueSelector(org.apache.rocketmq.client.producer.MessageQueueSelector messageQueueSelector)
public org.apache.rocketmq.client.producer.SendResult syncSend(String destination, org.springframework.messaging.Message<?> message)
Send message in synchronous mode. This method returns only when the sending procedure totally completes. Reliable synchronous transmission is used in extensive scenes, such as important notification messages, SMS notification, SMS marketing system, etc..
Warn: this method has internal retry-mechanism, that is, internal implementation will retry
DefaultMQProducer.getRetryTimesWhenSendFailed() times before claiming failure. As a result, multiple
messages may potentially delivered to broker(s). It's up to the application developers to resolve potential
duplication issue.
destination - formats: `topicName:tags`message - MessageSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSend(String destination, org.springframework.messaging.Message<?> message, long timeout)
syncSend(String, Message) with send timeout specified in addition.destination - formats: `topicName:tags`message - Messagetimeout - send timeout with millisSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSend(String destination, Collection<org.springframework.messaging.Message<?>> messages, long timeout)
destination - formats: `topicName:tags`messages - Collection of Messagetimeout - send timeout with millisSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSend(String destination, org.springframework.messaging.Message<?> message, long timeout, int delayLevel)
syncSend(String, Message) with send timeout specified in addition.destination - formats: `topicName:tags`message - Messagetimeout - send timeout with millisdelayLevel - level for the delay messageSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSend(String destination, Object payload)
syncSend(String, Message).destination - formats: `topicName:tags`payload - the Object to use as payloadSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSend(String destination, Object payload, long timeout)
syncSend(String, Object) with send timeout specified in addition.destination - formats: `topicName:tags`payload - the Object to use as payloadtimeout - send timeout with millisSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSendOrderly(String destination, org.springframework.messaging.Message<?> message, String hashKey)
syncSend(String, Message) with send orderly with hashKey by specified.destination - formats: `topicName:tags`message - MessagehashKey - use this key to select queue. for example: orderId, productId ...SendResultpublic org.apache.rocketmq.client.producer.SendResult syncSendOrderly(String destination, org.springframework.messaging.Message<?> message, String hashKey, long timeout)
syncSendOrderly(String, Message, String) with send timeout specified in addition.destination - formats: `topicName:tags`message - MessagehashKey - use this key to select queue. for example: orderId, productId ...timeout - send timeout with millisSendResultpublic org.apache.rocketmq.client.producer.SendResult syncSendOrderly(String destination, Object payload, String hashKey)
syncSend(String, Object) with send orderly with hashKey by specified.destination - formats: `topicName:tags`payload - the Object to use as payloadhashKey - use this key to select queue. for example: orderId, productId ...SendResultpublic org.apache.rocketmq.client.producer.SendResult syncSendOrderly(String destination, Object payload, String hashKey, long timeout)
syncSendOrderly(String, Object, String) with send timeout specified in addition.destination - formats: `topicName:tags`payload - the Object to use as payloadhashKey - use this key to select queue. for example: orderId, productId ...timeout - send timeout with millisSendResultpublic void asyncSend(String destination, org.springframework.messaging.Message<?> message, org.apache.rocketmq.client.producer.SendCallback sendCallback, long timeout, int delayLevel)
asyncSend(String, Message, SendCallback) with send timeout and delay level specified in addition.destination - formats: `topicName:tags`message - MessagesendCallback - SendCallbacktimeout - send timeout with millisdelayLevel - level for the delay messagepublic void asyncSend(String destination, org.springframework.messaging.Message<?> message, org.apache.rocketmq.client.producer.SendCallback sendCallback, long timeout)
asyncSend(String, Message, SendCallback) with send timeout specified in addition.destination - formats: `topicName:tags`message - MessagesendCallback - SendCallbacktimeout - send timeout with millispublic void asyncSend(String destination, org.springframework.messaging.Message<?> message, org.apache.rocketmq.client.producer.SendCallback sendCallback)
Send message to broker asynchronously. asynchronous transmission is generally used in response time sensitive business scenarios.
This method returns immediately. On sending completion, sendCallback will be executed.
Similar to syncSend(String, Object), internal implementation would potentially retry up to DefaultMQProducer.getRetryTimesWhenSendAsyncFailed() times before claiming sending failure, which may yield
message duplication and application developers are the one to resolve this potential issue.
destination - formats: `topicName:tags`message - MessagesendCallback - SendCallbackpublic void asyncSend(String destination, Object payload, org.apache.rocketmq.client.producer.SendCallback sendCallback, long timeout)
asyncSend(String, Object, SendCallback) with send timeout specified in addition.destination - formats: `topicName:tags`payload - the Object to use as payloadsendCallback - SendCallbacktimeout - send timeout with millispublic void asyncSend(String destination, Object payload, org.apache.rocketmq.client.producer.SendCallback sendCallback)
destination - formats: `topicName:tags`payload - the Object to use as payloadsendCallback - SendCallbackpublic void asyncSendOrderly(String destination, org.springframework.messaging.Message<?> message, String hashKey, org.apache.rocketmq.client.producer.SendCallback sendCallback, long timeout)
asyncSendOrderly(String, Message, String, SendCallback) with send timeout specified in
addition.destination - formats: `topicName:tags`message - MessagehashKey - use this key to select queue. for example: orderId, productId ...sendCallback - SendCallbacktimeout - send timeout with millispublic void asyncSendOrderly(String destination, org.springframework.messaging.Message<?> message, String hashKey, org.apache.rocketmq.client.producer.SendCallback sendCallback)
asyncSend(String, Message, SendCallback) with send orderly with hashKey by specified.destination - formats: `topicName:tags`message - MessagehashKey - use this key to select queue. for example: orderId, productId ...sendCallback - SendCallbackpublic void asyncSendOrderly(String destination, Object payload, String hashKey, org.apache.rocketmq.client.producer.SendCallback sendCallback)
destination - formats: `topicName:tags`payload - the Object to use as payloadhashKey - use this key to select queue. for example: orderId, productId ...sendCallback - SendCallbackpublic void asyncSendOrderly(String destination, Object payload, String hashKey, org.apache.rocketmq.client.producer.SendCallback sendCallback, long timeout)
asyncSendOrderly(String, Object, String, SendCallback) with send timeout specified in addition.destination - formats: `topicName:tags`payload - the Object to use as payloadhashKey - use this key to select queue. for example: orderId, productId ...sendCallback - SendCallbacktimeout - send timeout with millispublic void sendOneWay(String destination, org.springframework.messaging.Message<?> message)
One-way transmission is used for cases requiring moderate reliability, such as log collection.
destination - formats: `topicName:tags`message - Messagepublic void sendOneWay(String destination, Object payload)
sendOneWay(String, Message)destination - formats: `topicName:tags`payload - the Object to use as payloadpublic void sendOneWayOrderly(String destination, org.springframework.messaging.Message<?> message, String hashKey)
sendOneWay(String, Message) with send orderly with hashKey by specified.destination - formats: `topicName:tags`message - MessagehashKey - use this key to select queue. for example: orderId, productId ...public void sendOneWayOrderly(String destination, Object payload, String hashKey)
destination - formats: `topicName:tags`payload - the Object to use as payloadpublic void afterPropertiesSet()
throws Exception
afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBeanExceptionprotected void doSend(String destination, org.springframework.messaging.Message<?> message)
doSend 在类中 org.springframework.messaging.core.AbstractMessageSendingTemplate<String>protected org.springframework.messaging.Message<?> doConvert(Object payload, Map<String,Object> headers, org.springframework.messaging.core.MessagePostProcessor postProcessor)
doConvert 在类中 org.springframework.messaging.core.AbstractMessageSendingTemplate<String>public void destroy()
destroy 在接口中 org.springframework.beans.factory.DisposableBeanpublic org.apache.rocketmq.client.producer.TransactionSendResult sendMessageInTransaction(String txProducerGroup, String destination, org.springframework.messaging.Message<?> message, Object arg) throws org.springframework.messaging.MessagingException
txProducerGroup - the validate txProducerGroup name, set null if using the default namedestination - destination formats: `topicName:tags`message - message Messagearg - ext argorg.springframework.messaging.MessagingExceptionpublic void removeTransactionMQProducer(String txProducerGroup) throws org.springframework.messaging.MessagingException
Note: RocketMQTemplate can release all cached producers when bean destroying, it is not recommended to directly use this method by user.
txProducerGroup - org.springframework.messaging.MessagingExceptionpublic boolean createAndStartTransactionMQProducer(String txProducerGroup, RocketMQLocalTransactionListener transactionListener, ExecutorService executorService, org.apache.rocketmq.remoting.RPCHook rpcHook) throws org.springframework.messaging.MessagingException
Note: This method is invoked internally when processing @RocketMQLocalTransactionListener, it is not
recommended to directly use this method by user.
txProducerGroup - Producer (group) name, unique for each producertransactionListener - TransactoinListener impl classexecutorService - Nullable.rpcHook - Nullable.org.springframework.messaging.MessagingExceptionCopyright © 2019 Apache Software Foundation. All rights reserved.