Skip to content

Latest commit

 

History

History
62 lines (56 loc) · 2.92 KB

README.md

File metadata and controls

62 lines (56 loc) · 2.92 KB

Event Store Kafka

CDI extension for Java EE 8 application using Apache Kafka as Event Store.

Build Status License

Five minute start

How to quickly start using the Event Store Kafka with your Java EE 8 project.

Setup

  1. Add maven dependencies to your pom.xml
    <dependency>
        <groupId>net.osomahe</groupId>
        <artifactId>eventstore-kafka</artifactId>
        <version>0.4.3</version>
    </dependency>
  2. Added extensions src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
    net.osomahe.esk.EventStoreExtension
    

Producing events

  1. Extend AbstractEvent class
  2. Use EventStorePublisher#publish(event) method for publishing event to Apache Kafka synchronously. or
  3. Use EventStorePublisher#publishAsync(event) method for publishing event to Apache Kafka asynchronously.

Consuming events

  1. Extend AbstractEvent class or use the same as for publishing.
  2. Observes for CDI event
    public void handleCreate(@Observes TodoCreatedEvent event) {
        // do some magic with event
    }

Advanced

Configuration possibilities and default values. Unfortunately JavaEE 8 does not have any standard means of configuration and I didn't want to

Configuration

Unfortunately JavaEE 8 does not provide any standard way. There are two ways of configuring the eventstore-kafka.

  1. Application has to produce using @Produces and correct qualifier see example:
  • java.util.Properties with qualifiers @KafkaProducerConfig for overriding producer properties otherwise default values will be in place.
    Properties props = new Properties();
    props.put(BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    props.put(ACKS_CONFIG, "all");
  • java.util.Properties with qualifiers @KafkaConsumerConfig for overriding consumer properties otherwise default values will be in place.
    Properties props = new Properties();
    props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
    props.put(GROUP_ID_CONFIG, "client-application");
    props.put(AUTO_OFFSET_RESET_CONFIG, "earliest");
  1. Application has to implement EventStorePublisherConfig and (or) EventStoreConsumerConfig to provide non-default properties

Customization

  • @TopicName annotation for an event class to set different topic for given event(s)
  • @EventName annotation for an event class to set different event name
  • @AsyncEvent annotation for an event class to set asynchronous processing of events @ObeservesAsync required for handling async events