How to send Kafka message in SpringBoot

Поделиться
HTML-код
  • Опубликовано: 25 янв 2025

Комментарии • 1

  • @fvhiveproductionsbyLadyAga
    @fvhiveproductionsbyLadyAga  10 месяцев назад

    org.springframework.kafka
    spring-kafka
    -------------
    spring.kafka.consumer.bootstrap-servers = localhost:9092
    spring.kafka.consumer.group-id= group_id
    spring.kafka.consumer.auto-offset-reset = earliest
    spring.kafka.consumer.key-deserializer= org.apache.kafka.common.serialization.StringDeserializer
    spring.kafka.consumer.value-deserializer = org.apache.kafka.common.serialization.StringDeserializer
    spring.kafka.producer.bootstrap-servers = localhost:9092
    spring.kafka.producer.key-serializer = org.apache.kafka.common.serialization.StringSerializer
    spring.kafka.producer.value-serializer = org.apache.kafka.common.serialization.StringSerializer
    ---------------
    @Autowired
    KafkaTemplate template;
    @GetMapping("/test")
    public String hello() {
    template.send("testtopic1", "hello world from MS Ricky!! -> "+LocalDateTime.now());
    return "hello "+ LocalDateTime.now();
    }