com.alibaba.rocketmq.client.producer
类 DefaultMQProducer

java.lang.Object
  继承者 com.alibaba.rocketmq.client.ClientConfig
      继承者 com.alibaba.rocketmq.client.producer.DefaultMQProducer
所有已实现的接口:
MQAdmin, MQProducer
直接已知子类:
TransactionMQProducer

public class DefaultMQProducer
extends ClientConfig
implements MQProducer

消息生产者,适合使用spring初始化

从以下版本开始:
2013-7-25
作者:
shijia.wxr

字段摘要
protected  DefaultMQProducerImpl defaultMQProducerImpl
           
 
构造方法摘要
DefaultMQProducer()
           
DefaultMQProducer(String producerGroup)
           
 
方法摘要
 void createTopic(String key, String newTopic, int queueNum)
          创建topic
 long earliestMsgStoreTime(MessageQueue mq)
          向服务器查询队列保存的最早消息对应的存储时间
 List<MessageQueue> fetchPublishMessageQueues(String topic)
          根据topic获取对应的MessageQueue,如果是顺序消息,则按照顺序消息配置返回
 int getCompressMsgBodyOverHowmuch()
           
 String getCreateTopicKey()
           
 DefaultMQProducerImpl getDefaultMQProducerImpl()
           
 int getDefaultTopicQueueNums()
           
 int getMaxMessageSize()
           
 String getProducerGroup()
           
 int getRetryTimesWhenSendFailed()
           
 int getSendMsgTimeout()
           
 boolean isRetryAnotherBrokerWhenNotStoreOK()
           
 boolean isUnitMode()
           
 long maxOffset(MessageQueue mq)
          向服务器查询队列最大Offset PS: 最大Offset无对应消息,减1有消息
 long minOffset(MessageQueue mq)
          向服务器查询队列最小Offset PS: 最小Offset有对应消息
 QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end)
          根据消息Key查询消息
 long searchOffset(MessageQueue mq, long timestamp)
          根据时间查询对应的offset,精确到毫秒
P.S.
 SendResult send(Message msg)
          发送消息,同步调用
 SendResult send(Message msg, MessageQueue mq)
          向指定队列发送消息,同步调用
 SendResult send(Message msg, MessageQueueSelector selector, Object arg)
          发送消息,可以自定义选择队列,队列的总数可能会由于Broker的启停变化
如果要保证消息严格有序,在向运维人员申请Topic时,需要特别说明
同步调用
 void send(Message msg, MessageQueueSelector selector, Object arg, SendCallback sendCallback)
          发送消息,可以自定义选择队列,队列的总数可能会由于Broker的启停变化
如果要保证消息严格有序,在向运维人员申请Topic时,需要特别说明
异步调用
 void send(Message msg, MessageQueue mq, SendCallback sendCallback)
          向指定队列发送消息,异步调用
 void send(Message msg, SendCallback sendCallback)
          发送消息,异步调用
 TransactionSendResult sendMessageInTransaction(Message msg, LocalTransactionExecuter tranExecuter, Object arg)
           
 void sendOneway(Message msg)
          发送消息,Oneway形式,服务器不应答,无法保证消息是否成功到达服务器
 void sendOneway(Message msg, MessageQueue mq)
          向指定队列发送消息,Oneway形式,服务器不应答,无法保证消息是否成功到达服务器
 void sendOneway(Message msg, MessageQueueSelector selector, Object arg)
          发送消息,可以自定义选择队列,队列的总数可能会由于Broker的启停变化
如果要保证消息严格有序,在向运维人员申请Topic时,需要特别说明
Oneway形式,服务器不应答,无法保证消息是否成功到达服务器
 void setCompressMsgBodyOverHowmuch(int compressMsgBodyOverHowmuch)
           
 void setCreateTopicKey(String createTopicKey)
           
 void setDefaultTopicQueueNums(int defaultTopicQueueNums)
           
 void setMaxMessageSize(int maxMessageSize)
           
 void setProducerGroup(String producerGroup)
           
 void setRetryAnotherBrokerWhenNotStoreOK(boolean retryAnotherBrokerWhenNotStoreOK)
           
 void setRetryTimesWhenSendFailed(int retryTimesWhenSendFailed)
           
 void setSendMsgTimeout(int sendMsgTimeout)
           
 void setUnitMode(boolean isUnitMode)
           
 void shutdown()
          关闭服务,一旦关闭,此对象将不可用
 void start()
          启动服务
 MessageExt viewMessage(String msgId)
          根据消息ID,从服务器获取完整的消息
 
从类 com.alibaba.rocketmq.client.ClientConfig 继承的方法
buildMQClientId, cloneClientConfig, getClientCallbackExecutorThreads, getClientIP, getHeartbeatBrokerInterval, getInstanceName, getNamesrvAddr, getPersistConsumerOffsetInterval, getPollNameServerInteval, resetClientConfig, setClientCallbackExecutorThreads, setClientIP, setHeartbeatBrokerInterval, setInstanceName, setNamesrvAddr, setPersistConsumerOffsetInterval, setPollNameServerInteval, toString
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

字段详细信息

defaultMQProducerImpl

protected final transient DefaultMQProducerImpl defaultMQProducerImpl
构造方法详细信息

DefaultMQProducer

public DefaultMQProducer()

DefaultMQProducer

public DefaultMQProducer(String producerGroup)
方法详细信息

start

public void start()
           throws MQClientException
从接口 MQProducer 复制的描述
启动服务

指定者:
接口 MQProducer 中的 start
抛出:
MQClientException

shutdown

public void shutdown()
从接口 MQProducer 复制的描述
关闭服务,一旦关闭,此对象将不可用

指定者:
接口 MQProducer 中的 shutdown

fetchPublishMessageQueues

public List<MessageQueue> fetchPublishMessageQueues(String topic)
                                             throws MQClientException
从接口 MQProducer 复制的描述
根据topic获取对应的MessageQueue,如果是顺序消息,则按照顺序消息配置返回

指定者:
接口 MQProducer 中的 fetchPublishMessageQueues
参数:
topic - 消息Topic
返回:
返回队列集合
抛出:
MQClientException

send

public SendResult send(Message msg)
                throws MQClientException,
                       RemotingException,
                       MQBrokerException,
                       InterruptedException
从接口 MQProducer 复制的描述
发送消息,同步调用

指定者:
接口 MQProducer 中的 send
参数:
msg - 消息
返回:
发送结果
抛出:
MQClientException
RemotingException
MQBrokerException
InterruptedException

send

public void send(Message msg,
                 SendCallback sendCallback)
          throws MQClientException,
                 RemotingException,
                 InterruptedException
从接口 MQProducer 复制的描述
发送消息,异步调用

指定者:
接口 MQProducer 中的 send
参数:
msg - 消息
sendCallback - 发送结果通过此接口回调
抛出:
MQClientException
RemotingException
InterruptedException

sendOneway

public void sendOneway(Message msg)
                throws MQClientException,
                       RemotingException,
                       InterruptedException
从接口 MQProducer 复制的描述
发送消息,Oneway形式,服务器不应答,无法保证消息是否成功到达服务器

指定者:
接口 MQProducer 中的 sendOneway
参数:
msg - 消息
抛出:
MQClientException
RemotingException
InterruptedException

send

public SendResult send(Message msg,
                       MessageQueue mq)
                throws MQClientException,
                       RemotingException,
                       MQBrokerException,
                       InterruptedException
从接口 MQProducer 复制的描述
向指定队列发送消息,同步调用

指定者:
接口 MQProducer 中的 send
参数:
msg - 消息
mq - 队列
返回:
发送结果
抛出:
MQClientException
RemotingException
MQBrokerException
InterruptedException

send

public void send(Message msg,
                 MessageQueue mq,
                 SendCallback sendCallback)
          throws MQClientException,
                 RemotingException,
                 InterruptedException
从接口 MQProducer 复制的描述
向指定队列发送消息,异步调用

指定者:
接口 MQProducer 中的 send
参数:
msg - 消息
mq - 队列
sendCallback - 发送结果通过此接口回调
抛出:
MQClientException
RemotingException
InterruptedException

sendOneway

public void sendOneway(Message msg,
                       MessageQueue mq)
                throws MQClientException,
                       RemotingException,
                       InterruptedException
从接口 MQProducer 复制的描述
向指定队列发送消息,Oneway形式,服务器不应答,无法保证消息是否成功到达服务器

指定者:
接口 MQProducer 中的 sendOneway
参数:
msg - 消息
mq - 队列
抛出:
MQClientException
RemotingException
InterruptedException

send

public SendResult send(Message msg,
                       MessageQueueSelector selector,
                       Object arg)
                throws MQClientException,
                       RemotingException,
                       MQBrokerException,
                       InterruptedException
从接口 MQProducer 复制的描述
发送消息,可以自定义选择队列,队列的总数可能会由于Broker的启停变化
如果要保证消息严格有序,在向运维人员申请Topic时,需要特别说明
同步调用

指定者:
接口 MQProducer 中的 send
参数:
msg - 消息
selector - 队列选择器,发送时会回调
arg - 回调队列选择器时,此参数会传入队列选择方法
返回:
发送结果
抛出:
MQClientException
RemotingException
MQBrokerException
InterruptedException

send

public void send(Message msg,
                 MessageQueueSelector selector,
                 Object arg,
                 SendCallback sendCallback)
          throws MQClientException,
                 RemotingException,
                 InterruptedException
从接口 MQProducer 复制的描述
发送消息,可以自定义选择队列,队列的总数可能会由于Broker的启停变化
如果要保证消息严格有序,在向运维人员申请Topic时,需要特别说明
异步调用

指定者:
接口 MQProducer 中的 send
参数:
msg - 消息
selector - 队列选择器,发送时会回调
arg - 回调队列选择器时,此参数会传入队列选择方法
sendCallback - 发送结果通过此接口回调
抛出:
MQClientException
RemotingException
InterruptedException

sendOneway

public void sendOneway(Message msg,
                       MessageQueueSelector selector,
                       Object arg)
                throws MQClientException,
                       RemotingException,
                       InterruptedException
从接口 MQProducer 复制的描述
发送消息,可以自定义选择队列,队列的总数可能会由于Broker的启停变化
如果要保证消息严格有序,在向运维人员申请Topic时,需要特别说明
Oneway形式,服务器不应答,无法保证消息是否成功到达服务器

指定者:
接口 MQProducer 中的 sendOneway
参数:
msg - 消息
selector - 队列选择器,发送时会回调
arg - 回调队列选择器时,此参数会传入队列选择方法
抛出:
MQClientException
RemotingException
InterruptedException

sendMessageInTransaction

public TransactionSendResult sendMessageInTransaction(Message msg,
                                                      LocalTransactionExecuter tranExecuter,
                                                      Object arg)
                                               throws MQClientException
指定者:
接口 MQProducer 中的 sendMessageInTransaction
抛出:
MQClientException

createTopic

public void createTopic(String key,
                        String newTopic,
                        int queueNum)
                 throws MQClientException
从接口 MQAdmin 复制的描述
创建topic

指定者:
接口 MQAdmin 中的 createTopic
参数:
key - 请向运维人员申请
newTopic - 要创建的新topic
queueNum - 新topic队列数
抛出:
MQClientException

searchOffset

public long searchOffset(MessageQueue mq,
                         long timestamp)
                  throws MQClientException
从接口 MQAdmin 复制的描述
根据时间查询对应的offset,精确到毫秒
P.S. 当前接口有较多IO开销,请勿频繁调用

指定者:
接口 MQAdmin 中的 searchOffset
参数:
mq - 队列
timestamp - 毫秒形式时间戳
返回:
指定时间对应的offset
抛出:
MQClientException

maxOffset

public long maxOffset(MessageQueue mq)
               throws MQClientException
从接口 MQAdmin 复制的描述
向服务器查询队列最大Offset PS: 最大Offset无对应消息,减1有消息

指定者:
接口 MQAdmin 中的 maxOffset
参数:
mq - 队列
返回:
队列的最大Offset
抛出:
MQClientException

minOffset

public long minOffset(MessageQueue mq)
               throws MQClientException
从接口 MQAdmin 复制的描述
向服务器查询队列最小Offset PS: 最小Offset有对应消息

指定者:
接口 MQAdmin 中的 minOffset
参数:
mq - 队列
返回:
队列的最小Offset
抛出:
MQClientException

earliestMsgStoreTime

public long earliestMsgStoreTime(MessageQueue mq)
                          throws MQClientException
从接口 MQAdmin 复制的描述
向服务器查询队列保存的最早消息对应的存储时间

指定者:
接口 MQAdmin 中的 earliestMsgStoreTime
参数:
mq - 队列
返回:
最早消息对应的存储时间,精确到毫秒
抛出:
MQClientException

viewMessage

public MessageExt viewMessage(String msgId)
                       throws RemotingException,
                              MQBrokerException,
                              InterruptedException,
                              MQClientException
从接口 MQAdmin 复制的描述
根据消息ID,从服务器获取完整的消息

指定者:
接口 MQAdmin 中的 viewMessage
返回:
完整消息
抛出:
RemotingException
MQBrokerException
InterruptedException
MQClientException

queryMessage

public QueryResult queryMessage(String topic,
                                String key,
                                int maxNum,
                                long begin,
                                long end)
                         throws MQClientException,
                                InterruptedException
从接口 MQAdmin 复制的描述
根据消息Key查询消息

指定者:
接口 MQAdmin 中的 queryMessage
参数:
topic - 消息主题
key - 消息关键词
maxNum - 查询最大条数
begin - 起始时间戳
end - 结束时间戳
返回:
查询结果
抛出:
MQClientException
InterruptedException

getProducerGroup

public String getProducerGroup()

setProducerGroup

public void setProducerGroup(String producerGroup)

getCreateTopicKey

public String getCreateTopicKey()

setCreateTopicKey

public void setCreateTopicKey(String createTopicKey)

getSendMsgTimeout

public int getSendMsgTimeout()

setSendMsgTimeout

public void setSendMsgTimeout(int sendMsgTimeout)

getCompressMsgBodyOverHowmuch

public int getCompressMsgBodyOverHowmuch()

setCompressMsgBodyOverHowmuch

public void setCompressMsgBodyOverHowmuch(int compressMsgBodyOverHowmuch)

getDefaultMQProducerImpl

public DefaultMQProducerImpl getDefaultMQProducerImpl()

isRetryAnotherBrokerWhenNotStoreOK

public boolean isRetryAnotherBrokerWhenNotStoreOK()

setRetryAnotherBrokerWhenNotStoreOK

public void setRetryAnotherBrokerWhenNotStoreOK(boolean retryAnotherBrokerWhenNotStoreOK)

getMaxMessageSize

public int getMaxMessageSize()

setMaxMessageSize

public void setMaxMessageSize(int maxMessageSize)

getDefaultTopicQueueNums

public int getDefaultTopicQueueNums()

setDefaultTopicQueueNums

public void setDefaultTopicQueueNums(int defaultTopicQueueNums)

getRetryTimesWhenSendFailed

public int getRetryTimesWhenSendFailed()

setRetryTimesWhenSendFailed

public void setRetryTimesWhenSendFailed(int retryTimesWhenSendFailed)

isUnitMode

public boolean isUnitMode()

setUnitMode

public void setUnitMode(boolean isUnitMode)


Copyright © 2012-2014. All Rights Reserved.