com.alibaba.rocketmq.client.consumer
接口 MQPullConsumer

所有超级接口:
MQAdmin, MQConsumer
所有已知实现类:
DefaultMQPullConsumer

public interface MQPullConsumer
extends MQConsumer

消费者,主动方式消费

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

方法摘要
 long fetchConsumeOffset(MessageQueue mq, boolean fromStore)
          获取消费进度,返回-1表示出错
 Set<MessageQueue> fetchMessageQueuesInBalance(String topic)
          根据topic获取MessageQueue,以均衡方式在组内多个成员之间分配
 PullResult pull(MessageQueue mq, String subExpression, long offset, int maxNums)
          指定队列,主动拉取消息,即使没有消息,也立刻返回
 void pull(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback)
           
 PullResult pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums)
          指定队列,主动拉取消息,如果没有消息,则broker阻塞一段时间再返回(时间可配置)
broker阻塞期间,如果有消息,则立刻将消息返回
 void pullBlockIfNotFound(MessageQueue mq, String subExpression, long offset, int maxNums, PullCallback pullCallback)
           
 void registerMessageQueueListener(String topic, MessageQueueListener listener)
          注册监听队列变化的listener对象
 void shutdown()
          关闭服务
 void start()
          启动服务
 void updateConsumeOffset(MessageQueue mq, long offset)
          更新消费进度
只是更新Consumer缓存中的数据,如果是广播模式,则定时更新到本地存储
如果是集群模式,则定时更新到远端Broker

P.S.

 
从接口 com.alibaba.rocketmq.client.consumer.MQConsumer 继承的方法
fetchSubscribeMessageQueues, sendMessageBack
 
从接口 com.alibaba.rocketmq.client.MQAdmin 继承的方法
createTopic, earliestMsgStoreTime, maxOffset, minOffset, queryMessage, searchOffset, viewMessage
 

方法详细信息

start

void start()
           throws MQClientException
启动服务

抛出:
MQClientException

shutdown

void shutdown()
关闭服务


registerMessageQueueListener

void registerMessageQueueListener(String topic,
                                  MessageQueueListener listener)
注册监听队列变化的listener对象

参数:
topic -
listener - 一旦发生变化,客户端会主动回调listener对象

pull

PullResult pull(MessageQueue mq,
                String subExpression,
                long offset,
                int maxNums)
                throws MQClientException,
                       RemotingException,
                       MQBrokerException,
                       InterruptedException
指定队列,主动拉取消息,即使没有消息,也立刻返回

参数:
mq - 指定具体要拉取的队列
subExpression - 订阅过滤表达式字符串,broker依据此表达式进行过滤。目前只支持或运算
eg: "tag1 || tag2 || tag3"
如果subExpression等于null或者*,则表示全部订阅
offset - 从指定队列哪个位置开始拉取
maxNums - 一次最多拉取条数
返回:
参见PullResult
抛出:
MQClientException
InterruptedException
MQBrokerException
RemotingException

pull

void pull(MessageQueue mq,
          String subExpression,
          long offset,
          int maxNums,
          PullCallback pullCallback)
          throws MQClientException,
                 RemotingException,
                 InterruptedException
抛出:
MQClientException
RemotingException
InterruptedException

pullBlockIfNotFound

PullResult pullBlockIfNotFound(MessageQueue mq,
                               String subExpression,
                               long offset,
                               int maxNums)
                               throws MQClientException,
                                      RemotingException,
                                      MQBrokerException,
                                      InterruptedException
指定队列,主动拉取消息,如果没有消息,则broker阻塞一段时间再返回(时间可配置)
broker阻塞期间,如果有消息,则立刻将消息返回

参数:
mq - 指定具体要拉取的队列
subExpression - 订阅过滤表达式字符串,broker依据此表达式进行过滤。目前只支持或运算
eg: "tag1 || tag2 || tag3"
如果subExpression等于null或者*,则表示全部订阅
offset - 从指定队列哪个位置开始拉取
maxNums - 一次最多拉取条数
返回:
参见PullResult
抛出:
InterruptedException
MQBrokerException
RemotingException
MQClientException

pullBlockIfNotFound

void pullBlockIfNotFound(MessageQueue mq,
                         String subExpression,
                         long offset,
                         int maxNums,
                         PullCallback pullCallback)
                         throws MQClientException,
                                RemotingException,
                                InterruptedException
抛出:
MQClientException
RemotingException
InterruptedException

updateConsumeOffset

void updateConsumeOffset(MessageQueue mq,
                         long offset)
                         throws MQClientException
更新消费进度
只是更新Consumer缓存中的数据,如果是广播模式,则定时更新到本地存储
如果是集群模式,则定时更新到远端Broker

P.S. 可频繁调用,无性能开销

参数:
mq -
offset -
抛出:
MQClientException

fetchConsumeOffset

long fetchConsumeOffset(MessageQueue mq,
                        boolean fromStore)
                        throws MQClientException
获取消费进度,返回-1表示出错

参数:
mq -
fromStore -
返回:
抛出:
MQClientException

fetchMessageQueuesInBalance

Set<MessageQueue> fetchMessageQueuesInBalance(String topic)
                                              throws MQClientException
根据topic获取MessageQueue,以均衡方式在组内多个成员之间分配

参数:
topic - 消息Topic
返回:
返回队列集合
抛出:
MQClientException


Copyright © 2012-2014. All Rights Reserved.