How to implement contract testing when kafka is involved in microservice architecture?

I am currently working on a project that implements the implementation of kafka in the microservice architecture. Did you manage to create test cases for mS to interact with kafa using pact-jvm?

My implementation is microservice1 publishes a message to a REST client, which in turn sends a message to Kafka Topic. microservice2 uses the GET method to retrieve messages from a Kafka topic.

+6
source share
1 answer

Pact-JVM supports Message Packages that encapsulate a message that is consumed (one way) by some mechanism, usually a message queue. The idea is to test a consumer code that can consume a message through a consumer test, and then verify that the supplier generates the corresponding message. The actual message queue is not used in the test.

Message Queue Contract

It was originally designed to apply contract tests for Kafka's messaging services.

Tests are performed in two parts, like Request-Response Pact tests, except that the consumer reads the message during the consumer pact test and, if successful, the pact file is written. Then the provider code is called to generate the message, and this maps to what is in the pact file.

enter image description here

Pact-JVM:

+10

All Articles