Java Spring Boot + Kafka + Azure Event Hub for Kafka - Creating an Event Producer and Consumer

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • In this video, I am providing an example of how to develop an Event Producer and Consumer using Java Spring Boot.
    For the message broker, we will be using Kafka (running on Docker) for a development environment, and as a suggestion for a production environment, we will be using Azure Event Hub for Kafka.
    Libraries used:
    SpringDoc OpenAPI Starter WebMVC UI
    mvnrepository....
    Spring Cloud Starter Stream Kafka
    mvnrepository....
    Spring Cloud Azure Starter Integration Event Hubs
    mvnrepository....
    Repository with the complete code:
    github.com/pro...
    Kafka Configuration (local)
    Producer:
    spring:
    kafka:
    bootstrap-servers: localhost:9092
    producer:
    key-serializer: org.apache.kafka.common.serialization.StringSerializer
    value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
    Consumer:
    spring:
    kafka:
    bootstrap-servers: localhost:9092
    consumer:
    auto-offset-reset: earliest
    key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
    value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
    properties:
    spring.deserializer.key.delegate.class: org.apache.kafka.common.serialization.StringDeserializer
    spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer
    Azure Event Hub for Kafka Configuration
    Producer:
    spring:
    kafka:
    bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS}
    properties:
    security:
    protocol: SASL_SSL
    sasl:
    mechanism: PLAIN
    sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="\$\ConnectionString" password="{EVENT_HUB_CONNECTION_STRING}";
    producer:
    key-serializer: org.apache.kafka.common.serialization.StringSerializer
    value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
    Consumer:
    spring:
    kafka:
    bootstrap-servers: ${KAFKA_BOOTSTRAP_SERVERS}
    properties:
    security:
    protocol: SASL_SSL
    sasl:
    mechanism: PLAIN
    sasl.jaas.config: org.apache.kafka.common.security.plain.PlainLoginModule required username="\$\ConnectionString" password="{EVENT_HUB_CONNECTION_STRING}";
    consumer:
    auto-offset-reset: earliest
    key-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
    value-deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
    properties:
    spring.deserializer.key.delegate.class: org.apache.kafka.common.serialization.StringDeserializer
    spring.deserializer.value.delegate.class: org.springframework.kafka.support.serializer.JsonDeserializer
    #java #springboot #kafka #azureeventhub #producer #consumer #eventdriven

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