Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Consumer concurrency not working (all consumed message by same thread) #356

@lubos-bistak

Description

@lubos-bistak

Hello,

i built an application that writes and reads Java objects (serialized/deserialized using Avro) into a Kafka topic having 3 partitions by using Spring Cloud Stream. I want to read in parallel from this topic, but it seems not be working as always same thread handles the Java objects from this topic sequential.

Code to read from the topic looks like this:

@StreamListener(InputSink.INPUT_TOPIC1)
    public void readFromTopic1(SomeObject obj) {
        log.debug("[] Read from Kafka: {} ", Thread.currentThread().getName(),obj.toString());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

In logs i always see the same thread name "-L-1":
-L-1 Read from Kafka: ...

Application start-up logs:

[           -C-1] o.s.c.s.b.k.KafkaMessageChannelBinder$3  : partitions assigned:[topic1-2]
[           -C-1] o.s.c.s.b.k.KafkaMessageChannelBinder$3  : partitions assigned:[topic1-0]
[           -C-1] o.s.c.s.b.k.KafkaMessageChannelBinder$3  : partitions assigned:[topic1-1]

Configuration in application.yml:

spring:
  cloud:
    stream:
      default:
        contentType: application/*+avro
      bindings:
        outputTopic1
          destination: topic1
        inputTopic1:
          destination: topic1
          group: group-inputTopic1
          consumer:
            concurrency: 3
            partitioned: true
      schema:
        avro:
          dynamic-schema-generation-enabled: true

Spring dependencies:

  • spring-cloud-stream-reactive:1.3.0.RELEASE
  • spring-could-stream-schema:1.3.0.RELEASE
  • spring-cloud-starter-stream-kafka:1.3.0.RELEASE
  • spring-cloud-stream:1.3.0.RELEASE
  • spring-boot-starter-web:1.5.10.RELEASE

Thanks a lot for any advice !!!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions