1. Cannot execute transactional method because we are in an error state Caused by: org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
原因
sercurity.protocol 不全局化
解决方案
spring:
kafka:
bootstrap-servers:
properties:
security.protocol: SASL_PLAINTEXT
sasl.mechanism: SCRAM-SHA-256
sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="" password="";
改动为 ->
spring:
kafka:
bootstrap-servers:
producer:
acks: 1
security:
protocol: SASL_PLAINTEXT
properties:
sasl.mechanism: SCRAM-SHA-256
sasl.jaas.config: org.apache.kafka.common.security.scram.ScramLoginModule required username="" password="";
2. No transaction is in process; possible solutions: run the template operation within the scope of a template.executeInTransaction() operation, start a transaction with @Transactional before invoking the template method, run in a transaction started by a listener container when consuming a record
解决方案
在方法上加@Transactional注解
配置生产者 transaction-id-prefix:
3. Must set acks to all in order to use the idempotent producer. Otherwise we cannot guarantee idempotence.
解决方案
应答级别:多少个分区副本备份完成时向生产者发送ack确认(可选0、1、all/-1)
spring.kafka.producer.acks=-1