Java Spring Cloud Stream 3.0,kafka consumer在批处理模式下获取列表中的单个记录,而不是更多记录
正在尝试使用SpringCloudStream3.0以批处理模式使用kafka消息 消费者收到一个包含单个记录的列表,而不是更多记录 以下是yml,用户编码使用Java Spring Cloud Stream 3.0,kafka consumer在批处理模式下获取列表中的单个记录,而不是更多记录,java,apache-kafka,spring-kafka,spring-cloud-stream,spring-cloud-stream-binder-kafka,Java,Apache Kafka,Spring Kafka,Spring Cloud Stream,Spring Cloud Stream Binder Kafka,正在尝试使用SpringCloudStream3.0以批处理模式使用kafka消息 消费者收到一个包含单个记录的列表,而不是更多记录 以下是yml,用户编码使用 spring: cloud: stream: bindings: process-in-0: destination: person-command consumer: # maxAttempts: 1 batc
spring:
cloud:
stream:
bindings:
process-in-0:
destination: person-command
consumer:
# maxAttempts: 1
batch-mode: true
properties:
maxPollRecords: 10
minFetchBytes: 5000
fetchMaxWaitMs: 1000
消费者代码
@Transactional
@Bean
public Function<List<PersonEvent>, List<PersonEvent>> process() {
return pel ->{
List<Person> lstPerson = new ArrayList<Person>();
List<PersonEvent> lstPersonEvent = new ArrayList<PersonEvent>();
for (PersonEvent personEvent : pel) {
Person person = new Person();
person.setName(personEvent.getName());
lstPerson.add(person);
personEvent.setType("PersonSaved");
lstPersonEvent.add(personEvent);
}
logger.info("Person Size {}"+lstPerson.size());
Iterable<Person> savedPerson = repository.saveAll(lstPerson);
logger.info("Saved Person Size {}"+lstPerson.size());
return lstPersonEvent;
};
}
consumer下没有此类属性
属性
。在任何情况下,卡夫卡属性都不常见,需要指定为卡夫卡特定属性
看
此外,Spring Boot对任意Kafka属性一无所知,不会对它们执行camelCase转换。看
试一试
您可以通过检查Kafka客户端输出的信息日志来确认属性是否按预期设置。注意:日志语句中应该使用逗号,而不是加号。maxPollRecords是一个上限,而不是一个下限。而且,似乎您正在使用一个存储库,因此数据库。。。卡夫卡连接通常是该解决方案更合适的框架。属性设置不正确;看看我的答案。
2020-01-05 15:11:49.044 INFO 29590 --- [container-0-C-1] ication$$EnhancerBySpringCGLIB$$6d65e615 : Person Size {}1
2020-01-05 15:11:49.054 INFO 29590 --- [container-0-C-1] ication$$EnhancerBySpringCGLIB$$6d65e615 : Saved Person Size {}1
2020-01-05 15:11:50.045 INFO 29590 --- [container-0-C-1] ication$$EnhancerBySpringCGLIB$$6d65e615 : Person Size {}1
2020-01-05 15:11:50.053 INFO 29590 --- [container-0-C-1] ication$$EnhancerBySpringCGLIB$$6d65e615 : Saved Person Size {}1
spring:
cloud:
stream:
kafka:
bindings:
process-in-0:
consumer:
configuration:
max.poll.records: 10
min.fetch.bytes: 5000
fetch.max.wait.ms: 1000