org.apache.kafka.common.errors.topicauthorizationexception:无权访问主题:

g52tjvyc  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(635)

下面是我试图写Kafka主题的代码:

  1. @Service
  2. public class KafkaMessageSender {
  3. @Autowired
  4. KafkaTemplate<String, History> kafkaTemplate;
  5. @Value(value = "${my.kafka.topic}")
  6. private String topicName;
  7. @Autowired
  8. public KafkaMessageSender(KafkaTemplate<String, History> kafkaTemplate) {
  9. this.kafkaTemplate = kafkaTemplate;
  10. }
  11. public History writeToTopic(final History entry) throws Exception {
  12. try {
  13. String key = entry.getValue();
  14. SendResult<String,History> future = kafkaTemplate.send(topicName, key, entry).get();
  15. recordMetadata = future.getRecordMetadata();
  16. if (future.getRecordMetadata() != null) {
  17. LOGGER.info("message successfully sent to kafka);
  18. }
  19. } catch (KafkaException e) {
  20. }
  21. return entry;
  22. }

我和Kafka的关系还没有建立起来。不明白是什么问题。
下面是stacktrace:

  1. java.util.concurrent.ExecutionException: org.springframework.kafka.core.KafkaProducerException: Failed to send; nested exception is org.apache.kafka.common.errors.TopicAuthorizationException: Not authorized to access topics: [kaas.my_topic]
  2. at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:?]
  3. at java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[?:?]
  4. at org.springframework.util.concurrent.SettableListenableFuture.get(SettableListenableFuture.java:119) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
  5. at com.optum.chy.kafka.KafkaMessageSender.writeToTopic(KafkaMessageSender.java:42) ~[classes/:?]

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题