Skip to main content

Example Java Kafka Consumer

Source Code


Can I deploy Status

Pact Status (latest pact)

Pact Status (master/master pact)

This is an example of a Java kafka consumer that uses Pact, PactFlow and GitHub Actions to ensure that it is compatible with the expectations its consumers have of it.

The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.

See the canonical consumer example here: See also the full PactFlow CI/CD Workshop for which this can be substituted in as the "consumer".

In the following diagram, we'll be testing the "Product API", a simple HTTP service that exposes product information as a REST API, which is fed events from an Event API on the product topic.

Kafka Architecture




  • Running the API and kafka listener locally: make start
  • Producing test events into the product topic: make test-events
  • Retrieve latest products: curl localhost:8080/products