Exploring implementation details in code
There are several ways in which the producer-consumer pattern can be implemented in code. Some samples can be downloaded and run, along with custom implementations that you might find in domain libraries or core (shared) libraries. First, we will look at sample code that uses the Confluent
libraries for Kafka, which provide a simple and easy-to-understand abstraction layer for interacting with Kafka . The source projects for each of the components (producers and consumers) can be found in the chapter folder on GitHub, along with a bootstrap script to download and run Kafka locally. Please ensure that you have Docker installed, as the install is dependent upon running docker compose
. The start order for this example code will be to run docker compose up
, then to right-click on the consumer
project and select Debug > Start New Instance, then to right-click on the producer
project and select Debug > Start New Instance.