为什么springboot不选择apache Kafka bootstrap-servers in application.yml?

zqry0prt  于 2023-08-02  发布在  Apache
关注(0)|答案(1)|浏览(134)

我的Springboot应用程序似乎没有获取application.yml中提供的用于融合Kafka凭据的凭据。它能够选择其他凭据,如电子邮件,除了Kafka confluent,这让我意识到问题来自我的配置。我把他们提供给我的东西贴在他们的平台上。
我试着注解掉凭据,我注意到应用程序给出了同样的问题。这是我的配置。

  1. kafka:
  2. properties:
  3. sasl:
  4. mechanism: PLAIN
  5. jaas:
  6. enabled: true
  7. config: org.apache.kafka.common.security.plain.PlainLoginModule required username='<redacted>' password='<redacted>';
  8. bootstrap-servers: pkc-12p03.xxxxxx.azure.confluent.cloud:9092
  9. security:
  10. protocol: SASL_SSL
  11. session:
  12. timeout:
  13. ms: 5000
  14. basic:
  15. auth:
  16. credentials:
  17. source: USER_INFO
  18. user:
  19. info: <redacted>:<redacted>
  20. schema:
  21. registry:
  22. url: https://pkc-12p03.xxxx.azure.confluent.cloud:443

字符串
这是我在尝试访问端点时得到的响应

  1. 2023-07-26 15:43:10 [,] - INFO [Producer clientId=producer-1] Node -1 disconnected.
  2. 2023-07-26 15:43:10 [,] - WARN [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
  3. 2023-07-26 15:43:10 [,] - WARN [Producer clientId=producer-1] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
  4. 2023-07-26 15:43:11 [,] - INFO [Producer clientId=producer-1] Node -1 disconnected.
  5. 2023-07-26 15:43:11 [,] - WARN [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
  6. 2023-07-26 15:43:11 [,] - WARN [Producer clientId=producer-1] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected
  7. 2023-07-26 15:43:12 [,] - INFO [Producer clientId=producer-1] Node -1 disconnected.
  8. 2023-07-26 15:43:12 [,] - WARN [Producer clientId=producer-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.
  9. 2023-07-26 15:43:12 [,] - WARN [Producer clientId=producer-1] Bootstrap broker localhost:9092 (id: -1 rack: null) disconnected


它超时了。我就是这样使用Kafka的。这是一个简单的用法。

  1. public class MailServiceImpl implements MailService {
  2. private final JavaMailSender javaMailSender;
  3. private final MailConfiguration mailConfiguration;
  4. private final KafkaTemplate<String, MailRequestDto> kafkaTemplate;
  5. private final String topicName = "email_topic";
  6. @Override
  7. public BaseResponse<?> sendMail( MailRequestDto emailRequestDto) {
  8. MimeMessage message = javaMailSender.createMimeMessage();
  9. MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(message);
  10. try {
  11. mimeMessageHelper.setFrom(mailConfiguration.getMailUsername());
  12. mimeMessageHelper.setTo(emailRequestDto.getRecipient());
  13. mimeMessageHelper.setSubject(emailRequestDto.getSubject());
  14. mimeMessageHelper.setText(emailRequestDto.getText());
  15. javaMailSender.send(message);
  16. kafkaTemplate.send(topicName, emailRequestDto);
  17. Map<String, Object> responseData = buildResponseData(emailRequestDto);
  18. return buildSuccessResponse(responseData);
  19. } catch (MessagingException e) {
  20. return buildErrorResponse(e.getLocalizedMessage());
  21. }
  22. }
  23. }


在我的引导服务器上做telnet,我得到成功消息。有什么问题吗?我的pom.xml中有必要的依赖项

kmbjn2e3

kmbjn2e31#

请学习如何使用SO markdown来格式化代码(见我的编辑)。
你需要spring:作为第一个元素。
bootstrap-servers不应低于properties,而应低于spring.kafka
properties用于引导不直接暴露的Kafka属性。
https://docs.spring.io/spring-boot/docs/current/reference/html/messaging.html#messaging.kafka.additional-properties
否则,Sping Boot 将默认为127.0.0.1:9092

相关问题