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/08/20 03:20:53 UTC

[GitHub] dongeforever opened a new issue #419: 全局排序的Consumer

dongeforever opened a new issue #419: 全局排序的Consumer
URL: https://github.com/apache/rocketmq/issues/419
 
 
   RocketMQ的Topic的分队列存储的,队列的特点如下:
   1.单个队列内,按照发送时间进行排序;
   2.队列之间无序。
   
   有些场景,比如股票撮合,需要全局对多个队列进行排序。
   
   可以考虑在客户端实现一个全局排序的OrderedConsumer
   `
   class OrderedConsumer{
           //按照发送时间(getBornTimestamp)进行排序
          MessageExt receive();
   }
   `
   可以利用PullConsumer进行实现:
   ` Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues("TopicTest1");
           for (MessageQueue mq : mqs) {
               System.out.printf("Consume from the queue: %s%n", mq);
               SINGLE_MQ:
               while (true) {
                   try {
                       PullResult pullResult =
                           consumer.pullBlockIfNotFound(mq, null, getMessageQueueOffset(mq), 32);
                       System.out.printf("%s%n", 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();
                   }
               }
           }
   `
   
   实现时,可以逐步来,先假定MessageQueue的数量是固定。
   
   

----------------------------------------------------------------
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