本文整理汇总了Java中com.alibaba.rocketmq.client.consumer.PullResult类的典型用法代码示例。如果您正苦于以下问题:Java PullResult类的具体用法?Java PullResult怎么用?Java PullResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PullResult类属于com.alibaba.rocketmq.client.consumer包,在下文中一共展示了PullResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pullMessage
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
public PullResult pullMessage(//
final String addr,//
final PullMessageRequestHeader requestHeader,//
final long timeoutMillis,//
final CommunicationMode communicationMode,//
final PullCallback pullCallback//
) throws RemotingException, MQBrokerException, InterruptedException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);
switch (communicationMode) {
case ONEWAY:
assert false;
return null;
case ASYNC:
this.pullMessageAsync(addr, request, timeoutMillis, pullCallback);
return null;
case SYNC:
return this.pullMessageSync(addr, request, timeoutMillis);
default:
assert false;
break;
}
return null;
}
示例2: processPullResponse
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException {
PullStatus pullStatus = PullStatus.NO_NEW_MSG;
switch (response.getCode()) {
case ResponseCode.SUCCESS:
pullStatus = PullStatus.FOUND;
break;
case ResponseCode.PULL_NOT_FOUND:
pullStatus = PullStatus.NO_NEW_MSG;
break;
case ResponseCode.PULL_RETRY_IMMEDIATELY:
pullStatus = PullStatus.NO_MATCHED_MSG;
break;
case ResponseCode.PULL_OFFSET_MOVED:
pullStatus = PullStatus.OFFSET_ILLEGAL;
break;
default:
throw new MQBrokerException(response.getCode(), response.getRemark());
}
PullMessageResponseHeader responseHeader =
(PullMessageResponseHeader) response.decodeCommandCustomHeader(PullMessageResponseHeader.class);
return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(),
responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody());
}
示例3: main
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");
consumer.start();
try {
MessageQueue mq = new MessageQueue();
mq.setQueueId(0);
mq.setTopic("TopicTest3");
mq.setBrokerName("vivedeMacBook-Pro.local");
long offset = 26;
long beginTime = System.currentTimeMillis();
PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32);
System.out.println(System.currentTimeMillis() - beginTime);
System.out.println(pullResult);
}
catch (Exception e) {
e.printStackTrace();
}
consumer.shutdown();
}
示例4: pullMessage
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
/**
* 从对应地址拉取消息
*
* @param addr broker地址
* @param requestHeader
* @param timeoutMillis 客户端超时时间
* @param communicationMode 通信模式:异步,同步,单向
* @param pullCallback
* @return
* @throws RemotingException
* @throws MQBrokerException
* @throws InterruptedException
*/
public PullResult pullMessage(//
final String addr,//
final PullMessageRequestHeader requestHeader,//
final long timeoutMillis,//
final CommunicationMode communicationMode,//
final PullCallback pullCallback//
) throws RemotingException, MQBrokerException, InterruptedException {
RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.PULL_MESSAGE, requestHeader);
switch (communicationMode) {
case ONEWAY:
assert false; //拉取消息不允许是单向的
return null;
case ASYNC: //Push模式是异步拉取消息,同时需要传递一个callback
this.pullMessageAsync(addr, request, timeoutMillis, pullCallback);
return null;
case SYNC:
return this.pullMessageSync(addr, request, timeoutMillis);
default:
assert false;
break;
}
return null;
}
示例5: processPullResponse
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
private PullResult processPullResponse(final RemotingCommand response) throws MQBrokerException, RemotingCommandException {
PullStatus pullStatus = PullStatus.NO_NEW_MSG;
switch (response.getCode()) {
case ResponseCode.SUCCESS:
pullStatus = PullStatus.FOUND;
break;
case ResponseCode.PULL_NOT_FOUND:
pullStatus = PullStatus.NO_NEW_MSG;
break;
case ResponseCode.PULL_RETRY_IMMEDIATELY:
pullStatus = PullStatus.NO_MATCHED_MSG;
break;
case ResponseCode.PULL_OFFSET_MOVED:
pullStatus = PullStatus.OFFSET_ILLEGAL;
break;
default:
throw new MQBrokerException(response.getCode(), response.getRemark());
}
PullMessageResponseHeader responseHeader =
(PullMessageResponseHeader) response.decodeCommandCustomHeader(PullMessageResponseHeader.class);
return new PullResultExt(pullStatus, responseHeader.getNextBeginOffset(), responseHeader.getMinOffset(),
responseHeader.getMaxOffset(), null, responseHeader.getSuggestWhichBrokerId(), response.getBody());
}
示例6: main
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");
consumer.start();
try {
MessageQueue mq = new MessageQueue();
mq.setQueueId(0);
mq.setTopic("TopicTest3");
mq.setBrokerName("vivedeMacBook-Pro.local");
long offset = 26;
long beginTime = System.currentTimeMillis();
PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32);
System.out.println(System.currentTimeMillis() - beginTime);
System.out.println(pullResult);
}
catch (Exception e) {
e.printStackTrace();
}
consumer.shutdown();
}
示例7: testRecodeMessage
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
/**
* 实时更新offerset
*/
@Test
public void testRecodeMessage() {
long offset = 0;
try {
PullResult pullResult = consumer.pull(mq, null, offset, 9);
List<MessageExt> msgFoundList = pullResult.getMsgFoundList();
for (MessageExt ms : msgFoundList) {
long queueOffset = ms.getQueueOffset();
saveOfferSet(queueOffset, offsetStore, mq);
}
//更新offerset
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: broadCastMessage
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
/**
* 消费广播消息
*
* @throws com.alibaba.rocketmq.client.exception.MQClientException
* @throws com.alibaba.rocketmq.remoting.exception.RemotingException
* @throws com.alibaba.rocketmq.client.exception.MQBrokerException
* @throws InterruptedException
*/
@Test
public void broadCastMessage() throws MQClientException, RemotingException, MQBrokerException,
InterruptedException {
consumer.start();
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(topic);
System.out.println("mqs:" + mqs.size());
while (true) {
for (MessageQueue mq : mqs) {
PullResult pullResult =
consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq, false), 10);
putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
firePullResult(pullResult);
}
TimeUnit.SECONDS.sleep(2);
}
}
示例9: clusterMessage
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
/**
* 消费集群消息
*
* @throws com.alibaba.rocketmq.client.exception.MQClientException
* @throws com.alibaba.rocketmq.remoting.exception.RemotingException
* @throws InterruptedException
* @throws com.alibaba.rocketmq.client.exception.MQBrokerException
*/
@Test
public void clusterMessage() throws MQClientException, RemotingException, InterruptedException,
MQBrokerException {
consumer.setMessageModel(MessageModel.CLUSTERING);
consumer.start();
while (true) {
Set<MessageQueue> mqs = consumer.fetchMessageQueuesInBalance(topic);
System.out.println("mqs:" + mqs.size());
for (MessageQueue mq : mqs) {
PullResult pullResult = consumer.pull(mq, null, getMessageQueueOffset(mq, false), 10);
putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
firePullResult(pullResult);
}
TimeUnit.SECONDS.sleep(2);
}
}
示例10: firePullResult
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
private void firePullResult(PullResult pullResult) {
switch (pullResult.getPullStatus()) {
case FOUND:
for (MessageExt mex : pullResult.getMsgFoundList()) {
System.out.println(mex);
}
break;
case NO_MATCHED_MSG:
break;
case NO_NEW_MSG:
break;
case OFFSET_ILLEGAL:
break;
default:
break;
}
}
示例11: pullMessageSync
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
private PullResult pullMessageSync(//
final String addr,// 1
final RemotingCommand request,// 2
final long timeoutMillis// 3
) throws RemotingException, InterruptedException, MQBrokerException {
RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
assert response != null;
return this.processPullResponse(response);
}
示例12: main
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");
consumer.start();
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest1");
for (MessageQueue mq : mqs) {
System.out.println("Consume from the queue: " + mq);
SINGLE_MQ: while (true) {
try {
PullResult pullResult =
consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
System.out.println(pullResult);
putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
switch (pullResult.getPullStatus()) {
case FOUND:
break;
case NO_MATCHED_MSG:
break;
case NO_NEW_MSG:
break SINGLE_MQ;
case OFFSET_ILLEGAL:
break;
default:
break;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
consumer.shutdown();
}
示例13: main
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
final MQPullConsumerScheduleService scheduleService = new MQPullConsumerScheduleService("GroupName1");
scheduleService.setMessageModel(MessageModel.CLUSTERING);
scheduleService.registerPullTaskCallback("TopicTest1", new PullTaskCallback() {
@Override
public void doPullTask(MessageQueue mq, PullTaskContext context) {
MQPullConsumer consumer = context.getPullConsumer();
try {
long offset = consumer.fetchConsumeOffset(mq, false);
if (offset < 0)
offset = 0;
PullResult pullResult = consumer.pull(mq, "*", offset, 32);
System.out.println(offset + "\t" + mq + "\t" + pullResult);
switch (pullResult.getPullStatus()) {
case FOUND:
break;
case NO_MATCHED_MSG:
break;
case NO_NEW_MSG:
case OFFSET_ILLEGAL:
break;
default:
break;
}
consumer.updateConsumeOffset(mq, pullResult.getNextBeginOffset());
context.setPullNextDelayTimeMillis(100);
}
catch (Exception e) {
e.printStackTrace();
}
}
});
scheduleService.start();
}
示例14: pull
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
public void pull() throws Exception {
//获取订阅topic的queue
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest1");
for (MessageQueue mq : mqs) {
System.out.println("Consume from the queue: " + mq);
SINGLE_MQ:
while (true) {
try {//阻塞的拉去消息,中止时间默认20s
PullResult pullResult =
consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
System.out.println(Thread.currentThread().getName()+new Date()+""+pullResult);
putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
switch (pullResult.getPullStatus()) {
case FOUND://pullSataus
break;
case NO_MATCHED_MSG:
break;
case NO_NEW_MSG:
break SINGLE_MQ;
case OFFSET_ILLEGAL:
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例15: pullMessageSync
import com.alibaba.rocketmq.client.consumer.PullResult; //导入依赖的package包/类
private PullResult pullMessageSync(//
final String addr,// 1
final RemotingCommand request,// 2
final long timeoutMillis// 3
) throws RemotingException, InterruptedException, MQBrokerException {
RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
assert response != null;
return this.processPullResponse(response);
}