{"id":20772735,"url":"https://github.com/rcardin/kafka-testing","last_synced_at":"2025-06-13T02:33:00.098Z","repository":{"id":82060595,"uuid":"545684709","full_name":"rcardin/kafka-testing","owner":"rcardin","description":"Kafka Unit Testing Usine Spring Kafka and MockConsumer/MockProducer Classes","archived":false,"fork":false,"pushed_at":"2022-10-06T19:49:38.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-29T18:34:16.910Z","etag":null,"topics":["kafka","spring-kafka","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rcardin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-04T20:03:29.000Z","updated_at":"2024-05-14T12:44:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"dfad444a-17fc-4fc1-8611-35affd416afa","html_url":"https://github.com/rcardin/kafka-testing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rcardin/kafka-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fkafka-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fkafka-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fkafka-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fkafka-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rcardin","download_url":"https://codeload.github.com/rcardin/kafka-testing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rcardin%2Fkafka-testing/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259567063,"owners_count":22877634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kafka","spring-kafka","unit-testing"],"created_at":"2024-11-17T12:22:45.603Z","updated_at":"2025-06-13T02:33:00.037Z","avatar_url":"https://github.com/rcardin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kafka Unit Testing using Spring Kafka and `MockProducer`/`MockConsumer` Classes\n\nInside the Kafka library, there are two mock implementation of the `Consumer\u003cK, V\u003e` and\n`Producer\u003cK, V\u003e` interfaces. These classes are `MockConsumer` and `MockProducer`. These classes are\nuseful for unit testing Kafka consumers and producers. Please, refer to the official documentation\nto understand how to use them in the wild:\n\n* [How to build your first Apache KafkaProducer application](https://developer.confluent.io/tutorials/creating-first-apache-kafka-producer-application/confluent.html)\n* [How to build your first Apache KafkaConsumer application](https://developer.confluent.io/tutorials/creating-first-apache-kafka-consumer-application/confluent.html)\n\nThe [Spring Kafka](https://docs.spring.io/spring-kafka/docs/current/reference/html/) project is a\ngreat library to build client application using abstraction of the\nKafka consumers and producers managed by Spring. It abstracts the producer using a `KafkaTemplate\u003cK, V\u003e` type\n, and the annotation `@KafkaListener` to consume messages from a topic.\n\nCan we use the `MockConsumer` and `MockProducer` classes with Spring Kafka? The answer is yes, and\nthis is what this project is about.\n\nPlease, refer to the `src/test` folder to see how.\n\nIs the use of the `MockConsumer` and `MockProducer` classes with Spring Kafka a good idea? Well, I\ndon't think so. In the case of the consumer, we can call the method annotated with `@KafkaListener` \ndirectly. Otherwise, in the case of the producer, we can use the `KafkaTemplate\u003cK, V\u003e` type to \ncreate a mock using Mockito, or some other mocking framework.\n\n🤷‍♂️","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcardin%2Fkafka-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frcardin%2Fkafka-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frcardin%2Fkafka-testing/lists"}