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 2022/02/09 07:11:09 UTC

[GitHub] [rocketmq-spring] wz2cool edited a comment on issue #88: Consumer batch messages API.

wz2cool edited a comment on issue #88:
URL: https://github.com/apache/rocketmq-spring/issues/88#issuecomment-740458757


   Currently, I found a workaround to get batch messages. But we still perfer batch listener
    
   ```@RocketMQMessageListener(topic = "demo_product", consumerGroup = "demo_batch_product_consumerGroup", consumeMode = ConsumeMode.ORDERLY)
   public class ProductBatchConsumer implements RocketMQListener<String>, RocketMQPushConsumerLifecycleListener {
   
       private final Logger logger = LoggerFactory.getLogger(this.getClass());
   
       @Override
       public void onMessage(String message) {
           // do noting, have to implement RocketMQListener or throw error
       }
   
       private AtomicInteger atomicInteger = new AtomicInteger();
   
       @Override
       public void prepareStart(DefaultMQPushConsumer consumer) {
           consumer.setPullInterval(1000);
           consumer.setConsumeThreadMin(1);
           consumer.setConsumeThreadMax(1);
           consumer.setConsumeMessageBatchMaxSize(1000);
           consumer.setPullBatchSize(100);
           consumer.registerMessageListener((MessageListenerConcurrently) (msgs, context) -> {
               System.out.println("batchSize: " + msgs.size());
               int result = atomicInteger.addAndGet(msgs.size());
               System.out.println("totalSize: " + result);
               return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
           });
       }
   }```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org