question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with quarkus kafka smallrye consumer multithreading

See original GitHub issue

Describe the bug

By setting “partitions” parameter to 3. I have 3 different consumer ids, but the messages are processed sequentially.

  • quarkus version 2.X
  • smallrye

Properties that i set

mp:
  messaging:
    incoming:
      event:
        connector: smallrye-kafka
        auto:
          offset:
            reset: earliest
        topic: MY_TOPIC
        group:
          id: my-group
        partitions: 3

Expected behavior

the messages should be processed concurrently for each partition

Actual behavior

the messages are processed sequentialy though we have different partitions

Output of java -version

jdk11

Quarkus version or git rev

2.4.1

Build tool (ie. output of mvnw --version or gradlew --version)

3.6.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:23 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cescoffiercommented, Dec 8, 2021

Another solution is something like:


List<Executor> executors = ...

@Incoming("kafka")
@Outgoing("foo")
public Multi<Message<T>> dispatch(Multi<Message<T>> multi) {
   return multi.onItem().transformToUniAndMerge(msg -> {
       IncomingKafkaMetadata metadata = msg.getMetadata(IncomingKafkaMetadata.class).orElseThrow();
       int p = metadata.getPartition();
       Executor executor = executors.get(p);
       return Uni.createFrom().item(msg).emitOn(executor);
  }); 
}

Note that even with this, the emission will still be serialized. They would be multi-threaded, but serialized. You may want to do something like:

@Incoming("kafka")
@Outgoing("foo")
public Multi<Message<T>> dispatch(Multi<Message<T>> multi) {
   return multi.onItem().transformToUniAndMerge(msg -> {
       IncomingKafkaMetadata metadata = msg.getMetadata(IncomingKafkaMetadata.class).orElseThrow();
       int p = metadata.getPartition();
       Executor executor = executors.get(p);
       return Uni.createFrom().item(msg).emitOn(executor)
           .onItem().invoke(msg -> {
                    process(msg); msg.ack(); })
  }); 
}

so, the processing is running on the different threads.

You can try with the low-level kafka client, but it’s a rabbit hole.

1reaction
cescoffiercommented, Dec 7, 2021

No, the documentation is right, it just does not do the dispatching as you describe it, and will still serialize the records following the reactive streams semantic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with quarkus kafka smallrye consumer multithreading
I set this properties but, quarkus doesn't work correctly. smallrye; kafka have 3 partitions. mp: messaging: incoming: event: connector: ...
Read more >
Apache Kafka Reference Guide - Quarkus
Quarkus provides support for Apache Kafka through SmallRye Reactive Messaging framework. ... Multiple consumer threads inside a consumer group.
Read more >
Apache Kafka - SmallRye Reactive Messaging
The Kafka Producer is thread safe and may be used from multiple threads, so SmallRye Reactive Messaging exposes it directly. The Kafka Consumer...
Read more >
Quarkus — Subatomic Java Review: Apache Kafka Producer ...
In this article, we will develop consumer and producer applications for Apache Kafka using Quarkus Framework and create native images.
Read more >
Getting Started to Quarkus Reactive Messaging with Apache ...
Quarkus uses the SmallRye Reactive Messaging project to interact with ... (smallrye-kafka-consumer-thread-0) SRMSG18257: Kafka consumer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found