You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2018/12/21 03:13:10 UTC

[GitHub] sailliu opened a new issue #618: DefaultMQPullConsumer

sailliu opened a new issue #618: DefaultMQPullConsumer
URL: https://github.com/apache/rocketmq/issues/618
 
 
   DefaultMQPullConsumer  MessageModel  BROADCASTING,how update offset to broker?
   ```
   public class PullConsumer {
   	private static final Map<MessageQueue, Long> offsetTable = new HashMap<MessageQueue, Long>();
   	public static void main(String[] args) throws Exception {
   		DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("pullConsumer");
   		consumer.setNamesrvAddr("192.168.159.128:9876;192.168.159.129:9876");
   		consumer.start();
   		try {
   			Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest");
   			for(MessageQueue mq:mqs) {
   				System.out.println("Consume from the queue: " + mq);
   			//	long offset = consumer.fetchConsumeOffset(mq, true);
   			//	PullResultExt pullResult =(PullResultExt)consumer.pull(mq, null, getMessageQueueOffset(mq), 32);
   				PullResultExt pullResult =(PullResultExt)consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
   				putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
   				switch (pullResult.getPullStatus()) {
                   case FOUND:
                       List<MessageExt> messageExtList = pullResult.getMsgFoundList();
                       for (MessageExt m : messageExtList) {
                           System.out.println(new String(m.getBody()));
                       }
                       break;
                   case NO_MATCHED_MSG:
                       break;
                   case NO_NEW_MSG:
                       break ;
                   case OFFSET_ILLEGAL:
                       break;
                   default:
                       break;
   				}
   			}
   		} catch (MQClientException e) {
   			e.printStackTrace();
   		}
   		
   		
   	}
   	
   	private static void putMessageQueueOffset(MessageQueue mq, long offset) {
           offsetTable.put(mq, offset);
       }
    
       private static long getMessageQueueOffset(MessageQueue mq) {
           Long offset = offsetTable.get(mq);
           if (offset != null)
               return offset;
           return 0;
       }
   }

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services