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.

How to define a single threaded handler for multiple sink bindings or input destinations?

See original GitHub issue

I have a requirement to check if spring cloud streams supports single threaded handler for multiple input bindings. If I configure my app to have a single binding with 2 destination:

spring:
  cloud:
    stream:
      defaultBinder: kafka
      bindings:
        input:
          destination: c1,c2
          group: mygroup
          consumer:
            partitioned: true

and a listener:

    @StreamListener("input")
    public void receive(Message<?> message) {
        System.out.println("["+Thread.currentThread().getId()+"] Received1 message "+message);
    }

I see that the message are consumed with 2 different threads:

[38] Received1 message ...
[30] Received1 message ...

Is there anyway to configure my app so I can control the number of handling threads, regardless of the number of the binding\destinations configured?

Noticed that if I do similar thing using spring-kafka, I do see that the messages are handled by a single thread:

kafka:
  consumer:
    bootstrap: localhost:9092
    group: mygroup
    topic:
      - c1
      - c2

and:

   @KafkaListener(topics = {"c1","c2"})
    public void onReceiving(String msg, @Header(KafkaHeaders.OFFSET) Integer offset,
                            @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition,
                            @Header(KafkaHeaders.RECEIVED_TOPIC) String topic) {
        System.out.println("["+Thread.currentThread().getId()+"] Processing msg = "+msg+", topic = "+topic+", partition = "+partition);
    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
olegzcommented, Jan 2, 2018

If we want to use this one, i’d rather change the title of it a bit since there are now two things discussed and interestingly enough the one we’re discussing now is not actually related to the issue clarified by @fghawi , so I prefer to raise new one and link o this one for details

1reaction
garyrussellcommented, Jan 2, 2018

Both containers (RabbitMQ and Kafka) support consuming from multiple queues/topics, but the binder doesn’t work that way - each destination gets its own container.

I suggested some time ago that we should add an option to support multi-destination per container, but it never got any priority. We should reconsider, I guess.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide for Kafka Connector Developers
Kafka Connect is intended to define bulk data copying jobs, such as copying an entire database rather than creating many jobs to copy...
Read more >
Multithreading and Concurrency - Java Programming Tutorial
A multi-thread program has an initial entry point (the main() method), followed by many entry and exit points, which are run concurrently with...
Read more >
Spring Cloud Stream Kafka Binder Reference Guide
Multiple Input Bindings ; Multiple Output Bindings ... The Apache Kafka Binder implementation maps each destination to an Apache Kafka topic.
Read more >
Apache Kafka Reference Guide - Quarkus
Reactive Messaging invokes your method on an I/O thread. ... One use case is to dynamically select the destination topic of a message....
Read more >
Using Combine
There are two subscribers built-in to Combine: Assign and Sink. There is a subscriber ... Combine is not just a single threaded construct....
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