Putting it all together

Now that we have everything set up, its time to wiring it together:

public class App {

  public static void main(String[] args) {
    Properties streamsConfig = new Properties();
    streamsConfig.put(StreamsConfig.APPLICATION_ID_CONFIG, "customer-service");
    streamsConfig.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");

    Eventify eventify = Eventify.builder()
        .streamsConfig(streamsConfig)
        .registerHandler(new CustomerCommandHandler())
        .registerHandler(new CustomerEventSourcingHandler())
        .registerHandler(new CustomerEventHandler())
        .build();

    eventify.start();
  }
}

Spring Boot

If you are using Spring Boot with the eventify-spring-boot-starter dependency, your handlers will be registered automatically:

@Configuration
public class EventifyConfig {

  @Bean
  public Eventify eventify() {
    Properties streamsConfig = new Properties();
    streamsConfig.put(StreamsConfig.APPLICATION_ID_CONFIG, "customer-service");
    streamsConfig.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");

    return Eventify.builder()
        .streamsConfig(streamsConfig)
        .build();
  }

  @Bean
  public CommandGateway commandGateway() {
    Properties producerConfig = new Properties();
    producerConfig.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);

    return CommandGateway.builder()
        .producerConfig(producerConfig)
        .replyTopic("my-reply-topic")
        .build();
  }
}