Домой United States USA — software Ports and Adapters Architecture With Kafka, Avro, and Spring-Boot

Ports and Adapters Architecture With Kafka, Avro, and Spring-Boot

382
0
ПОДЕЛИТЬСЯ

In this post, we will be implementing a Kafka Producer and Consumer using the Ports and Adapters (a.k.a. Hexagonal) architecture.
Join the DZone community and get the full member experience. In this post, we will be implementing a Kafka Producer and Consumer using the Ports and Adapters (a.k.a. Hexagonal) architecture. We will also be using the KafkaAvroSerializer to send specific Avro types using Kafka and the Kafka Schema Registry. The overall workflow is something like this: a domain object (Person.java) is sent from BusinessDomainService to Kafka where it gets serialized to Avro object (PersonDto.java); which is then consumed from the Kafka topic via a Kafka Consumer and translated from Avro object (PersonDto.java) back to domain object (Person.java) before being sent back to BusinessDomainService for some arbitrary post-processing. The whole flow is a little contrived in that we are sending a Kafka message half-way around the world only to arrive for post-processing back in BusinessDomainService, but, in my opinion, it nicely closes the loop so I am keeping it like that. In terms of implementation, we will be going with a multi-module maven project, and here is the list of modules that we will need. This being a Spring Boot application, this module houses the main @SpringBootApplication class to jump-start the application. This is the core business/functional module and it is here that all our business service classes (BusinessDomainService.java) and business domain model classes (Person.java) live. In terms of dependencies, true to its Hexagonal Architecture, the domain module has no inward dependency; this is the core business domain module and should, therefore, not know anything about the outside world. Here sits the business logic of your application. The goal is to have it written in plain language so that an analyst or even non-technical person could understand. Inside of it, we use a domain-specific language, which can be easily understood by business people.

Continue reading...