@KafkaListener(
id = "concurrencyConsumer",
topics = "#{'${kafka.listener.multiple.partition.topic}'.split(',')}",
containerFactory = "ackConcurrencyContainerFactory")
public void consumerListener(List consumerRecords, Acknowledgment ack) {
LogRecord.handle(consumerRecords, ack);
}
@KafkaListener(
id = "singleConsumer",
topics = "#{'${kafka.listener.single.partition.topic}'.split(',')}",
containerFactory = "ackSingleContainerFactory")
public void inputPersonfileNewCluster(List consumerRecords, Acknowledgment ack) {
LogRecord.handle(consumerRecords, ack);
}
@Bean("ackConcurrencyContainerFactory")
public ConcurrentKafkaListenerContainerFactory ackContainerFactory() {
ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory();
factory.setConsumerFactory(new DefaultKafkaConsumerFactory(consumerProps()));
factory.getContainerProperties().setAckMode(AbstractMessageListenerContainer.AckMode.MANUAL_IMMEDIATE);
factory.setBatchListener(true);
factory.setConcurrency(concurrency);
return factory;
}
INFO|2019-04-17 21:53:04.079|[singleConsumer-0-L-1 ]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test,partition = 0, offset = 0,value = fo": "{\"c,Time: Wed Apr 17 21:53:04 CST 2019
INFO|2019-04-17 21:53:04.080|[concurrencyConsumer-0-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 0, offset = 0,value = fo": "{\"c,Time: Wed Apr 17 21:53:04 CST 2019
INFO|2019-04-17 21:53:04.137|[concurrencyConsumer-2-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 2, offset = 0,value = fo": "{\"c,Time: Wed Apr 17 21:53:04 CST 2019
INFO|2019-04-17 21:53:04.153|[concurrencyConsumer-3-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 3, offset = 0,value = fo": "{\"c,Time: Wed Apr 17 21:53:04 CST 2019
INFO|2019-04-17 21:53:04.168|[concurrencyConsumer-1-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 1, offset = 0,value = fo": "{\"c,Time: Wed Apr 17 21:53:04 CST 2019
INFO|2019-04-17 21:53:07.848|[singleConsumer-0-L-1 ]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test,partition = 0, offset = 10000,value = fo": "{\"c,Time: Wed Apr 17 21:53:07 CST 2019
INFO|2019-04-17 21:53:07.914|[concurrencyConsumer-0-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 0, offset = 10000,value = fo": "{\"c,Time: Wed Apr 17 21:53:07 CST 2019
INFO|2019-04-17 21:53:07.962|[concurrencyConsumer-2-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 2, offset = 10000,value = fo": "{\"c,Time: Wed Apr 17 21:53:07 CST 2019
INFO|2019-04-17 21:53:08.200|[concurrencyConsumer-3-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 3, offset = 10000,value = fo": "{\"c,Time: Wed Apr 17 21:53:08 CST 2019
INFO|2019-04-17 21:53:08.506|[concurrencyConsumer-1-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 1, offset = 10000,value = fo": "{\"c,Time: Wed Apr 17 21:53:08 CST 2019
INFO|2019-04-17 21:53:11.559|[concurrencyConsumer-0-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 0, offset = 20000,value = fo": "{\"c,Time: Wed Apr 17 21:53:11 CST 2019
INFO|2019-04-17 21:53:11.618|[concurrencyConsumer-2-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 2, offset = 20000,value = fo": "{\"c,Time: Wed Apr 17 21:53:11 CST 2019
INFO|2019-04-17 21:53:11.862|[concurrencyConsumer-3-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 3, offset = 20000,value = fo": "{\"c,Time: Wed Apr 17 21:53:11 CST 2019
INFO|2019-04-17 21:53:12.131|[concurrencyConsumer-1-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 1, offset = 20000,value = fo": "{\"c,Time: Wed Apr 17 21:53:12 CST 2019
INFO|2019-04-17 21:53:13.311|[singleConsumer-0-L-1 ]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test,partition = 0, offset = 20000,value = fo": "{\"c,Time: Wed Apr 17 21:53:13 CST 2019
INFO|2019-04-17 21:53:14.986|[concurrencyConsumer-0-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 0, offset = 30000,value = fo": "{\"c,Time: Wed Apr 17 21:53:14 CST 2019
INFO|2019-04-17 21:53:15.047|[concurrencyConsumer-2-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 2, offset = 30000,value = fo": "{\"c,Time: Wed Apr 17 21:53:15 CST 2019
INFO|2019-04-17 21:53:15.256|[concurrencyConsumer-3-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 3, offset = 30000,value = fo": "{\"c,Time: Wed Apr 17 21:53:15 CST 2019
INFO|2019-04-17 21:53:15.676|[concurrencyConsumer-1-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 1, offset = 30000,value = fo": "{\"c,Time: Wed Apr 17 21:53:15 CST 2019
INFO|2019-04-17 21:53:17.396|[singleConsumer-0-L-1 ]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test,partition = 0, offset = 30000,value = fo": "{\"c,Time: Wed Apr 17 21:53:17 CST 2019
INFO|2019-04-17 21:53:19.376|[concurrencyConsumer-0-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 0, offset = 40000,value = fo": "{\"c,Time: Wed Apr 17 21:53:19 CST 2019
INFO|2019-04-17 21:53:19.586|[concurrencyConsumer-2-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 2, offset = 40000,value = fo": "{\"c,Time: Wed Apr 17 21:53:19 CST 2019
INFO|2019-04-17 21:53:19.708|[concurrencyConsumer-3-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 3, offset = 40000,value = fo": "{\"c,Time: Wed Apr 17 21:53:19 CST 2019
INFO|2019-04-17 21:53:20.099|[concurrencyConsumer-1-L-1]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test1,partition = 1, offset = 40000,value = fo": "{\"c,Time: Wed Apr 17 21:53:20 CST 2019
INFO|2019-04-17 21:53:21.908|[singleConsumer-0-L-1 ]|c.i.m.c.LogRecord.logRecode. 23|消费数据: topic = test,partition = 0, offset = 40000,value = fo": "{\"c,Time: Wed Apr 17 21:53:21 CST 2019
INFO|2019-04-17 21:55:04.030|[concurrencyConsumer-4-C-1]|o.a.k.c.c.i.AbstractCoordinator.sendJoinGroupRequest. 486|[Consumer clientId=consumer-5, groupId=test-group-xn-03] (Re-)joining group
INFO|2019-04-17 21:55:04.030|[concurrencyConsumer-5-C-1]|o.a.k.c.c.i.AbstractCoordinator.sendJoinGroupRequest. 486|[Consumer clientId=consumer-6, groupId=test-group-xn-03] (Re-)joining group
https://gitee.com/mozping/total-learn/tree/master/mozping-msg-queue/msg-queue-consumer-test