rocketmq想支持批量消费,于是便设置以下参数:
consumer.setConsumeMessageBatchMaxSize(1000);
这样是正确的,但由于业务要求,还想再设置大点,于是设置成这样:
consumer.setConsumeMessageBatchMaxSize(10000);
报错了。直接不消费了。
错误原因写的很明显,这个consumeMessageBatchMaxSize只支持0到1024,超出范围就直接启动消费者失败。
下面是报错信息:
com.alibaba.rocketmq.client.exception.MQClientException: consumeMessageBatchMaxSize Out of range [1, 1024]
See https://github.com/alibaba/RocketMQ/issues/73 for further details.at com.alibaba.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl.checkConfig(DefaultMQPushConsumerImpl.java:910) ~[rocketmq-client-3.2.2.R3.FB-20160704.105459-1.jar:na]at com.alibaba.rocketmq.client.impl.consumer.DefaultMQPushConsumerImpl.start(DefaultMQPushConsumerImpl.java:695) ~[rocketmq-client-3.2.2.R3.FB-20160704.105459-1.jar:na]at com.alibaba.rocketmq.client.consumer.DefaultMQPushConsumer.start(DefaultMQPushConsumer.java:385) ~[rocketmq-client-3.2.2.R3.FB-20160704.105459-1.jar:na]at com.yeahmobi.dsp.adconsumer.helper.AbstractPullConsumer2ForBatch.afterPropertiesSet(AbstractPullConsumer2ForBatch.java:173) ~[dsp-track-consumer-0.0.1-SNAPSHOT.jar:na]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:751) [spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) [spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) [spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
看源码:
这个值默认是1,也就是rocketmq默认只能一条一条消费。
再看这段,直接判断范围,不在0到1024就报错了。
问题很明显,但仔细想想这是为什么呢?
为什么这个值不让超过1024,也就是rocketmq的作者,不希望每批处理的条数超过1024条。
个人猜测
1、如果一批消费太多的话,量可能会有点太大,导致传输解析变慢。
2、如果失败重试,这么多绑在一起,可能就因为某一条出错,而导致整体重试,所以这个整体也不能太大,否则也是很麻烦的。