Skip to content

Allow multi-threaded access to KafkaConsumer #613

@Hc747

Description

@Hc747

Feature description

Problem:
A KafkaConsumer instance can be safely shared between threads when all access is mutually exclusive. Improper access results in a ConcurrentModificationException being raised - as per the documentation.

Micronaut's current implementation does not ensure that access to a KafkaConsumer is mutually exclusive, and as a consequence, downstream code is unable to perform operations with the KafkaConsumer instance outside of the poll loop thread. This is prohibitive as it prevents multi-threaded code from utilising all of the niceties of Micronaut's Kafka implementation and life-cycle management.

Feature Request:
To ensure that Micronaut's use of KafkaConsumers is mutually exclusive, achieved by performing Kafka operations within a synchronized block.

Implementation:

  • Synchronise access to KafkaConsumer instances within the KafkaConsumerProcessor when performing Kafka operations.
  • Update documentation in ConsumerRegistry#getConsumer.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions