Skip to content

Use interface versions for Producer and Consumer #1

@empperi

Description

@empperi

Currently code uses directly org.apache.kafka.clients.producer.KafkaProducer and org.apache.kafka.clients.consumer.KafkaConsumer. Code should use org.apache.kafka.clients.producer.Producer and org.apache.kafka.clients.consumer.Consumer interfaces instead.

Why this matters? Because Kafka Java client library provides both MockConsumer and MockProducer out of the box which implement those interfaces. This allows one to use those mock implementations in place of the actual Kafka* versions when doing unit testing. Now however since code uses the Kafka* versions directly with type hints in function signature one gets a java.lang.ClassCastException when calling those functions with mock implementations.

One can go around this via proxy but that requires manual setup and creating your own mock implementations. Since Kafka Client library provides these out of the box they should be preferred.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions