Java Spring Boot Kafka嵌入Kafka事务
嗨,我想用卡夫卡测试卡夫卡消费者方法。我有这个方法:Java Spring Boot Kafka嵌入Kafka事务,java,spring-boot,testing,apache-kafka,transactions,Java,Spring Boot,Testing,Apache Kafka,Transactions,嗨,我想用卡夫卡测试卡夫卡消费者方法。我有这个方法: @KafkaListener(topics = TOPIC_OWNER) @Transactional("chainedKafkaTransactionManager") public void consumeFromOwnerTopic(ConsumerRecord<String, AccessAvro> accessAvro) { final UUID userId = textMapper.toU
@KafkaListener(topics = TOPIC_OWNER)
@Transactional("chainedKafkaTransactionManager")
public void consumeFromOwnerTopic(ConsumerRecord<String, AccessAvro> accessAvro) {
final UUID userId = textMapper.toUUID(accessAvro.value().getUserId());
User user = getUserFromDatabase(userId);
userRepository.save(user);
}
}
@KafkaListener(topics=TOPIC\u所有者)
@事务性(“chainedKafkaTransactionManager”)
public void consumerfromOwnerTopic(ConsumerRecord accessAvro){
最终UUID userId=textMapper.touid(accessAvro.value().getUserId());
User User=getUserFromDatabase(userId);
userRepository.save(用户);
}
}
试验
@SpringBootTest
@ActiveProfiles(“测试”)
@TestPropertySource(locations=“classpath:bootstrap test.yml”)
@EmbeddedKafka(partitions=1,topics=“access owner”,bootstrapServersProperty=
“spring.kafka.bootstrap服务器”)
类AccessConsumerTest扩展了规范{
@自动连线
私有KafkaTemplate模板
准备访问访问访问访问访问(){
AccessAvro AccessAvro=新AccessAvro();
accessAvro.restaurantId=UUID.randomuid().toString()
accessAvro.userId=UUID.randomUUID().toString()
返回存取器
}
def“应该从已使用的主题添加角色”(){
鉴于:
sendKafkaAcces()
期望:
1==1
}
私有上市未来sendKafkaAcces(){
发送(“访问所有者”,prepareAccessAvro())
}
}
在以下情况下,我的交易有错误:
- 我将注释@Transaction(“链接…”)添加到测试方法中,我对副本有错误
- 尝试删除“transaction id prefix”表单属性,我对ChainedKafkatTransaction.class bc有错误。正在尝试在属性中查找它
- 当我尝试不在测试方法上添加@Transaction时,出现错误:在事务中运行 我如何测试它
org.springframework.transaction.CannotCreateTransactionException: Could not create
Kafka transaction; nested exception is
org.apache.kafka.common.errors.TimeoutException: Timeout expired after
60000milliseconds while awaiting InitProducerId; nested exception is
org.springframework.transaction.CannotCreateTransactionException: Could not create
Kafka transaction; nested exception is
org.apache.kafka.common.errors.TimeoutException: Timeout expired after
60000milliseconds while awaiting InitProducerId
原因:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为“org.springframework.kafka.transaction.KafkaTransactionManager”的合格bean可用:至少需要1个符合autowire候选条件的bean。依赖项注释:{}
有什么错误?
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
948 ERROR 5020 --- [quest-handler-7] kafka.server.KafkaApis :
[KafkaApi-0] Number of alive brokers '1' does not meet the required replication factor
'3' for the transactions state topic (configured via
'transaction.state.log.replication.factor'). This error can be ignored if the cluster
is starting up and not all brokers are up yet.
2020-11-10 22:18:53.023 WARN 5020 --- [ main]
o.s.test.context.TestContextManager : Caught exception while invoking
'beforeTestMethod' callback on TestExecutionListener
org.springframework.transaction.CannotCreateTransactionException: Could not create
Kafka transaction; nested exception is
org.apache.kafka.common.errors.TimeoutException: Timeout expired after
60000milliseconds while awaiting InitProducerId; nested exception is
org.springframework.transaction.CannotCreateTransactionException: Could not create
Kafka transaction; nested exception is
org.apache.kafka.common.errors.TimeoutException: Timeout expired after
60000milliseconds while awaiting InitProducerId