Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kafka] One consumer for multiple kafka topics #832

Closed
koderoff opened this issue Apr 27, 2019 · 14 comments
Closed

[kafka] One consumer for multiple kafka topics #832

koderoff opened this issue Apr 27, 2019 · 14 comments
Assignees
Labels
enhancement pr needed closed bugs or features issues that require a PR. Because there is noone is willig to contribute it wontfix

Comments

@koderoff
Copy link

I have several topics which are being populated by a separate app. Is there a way to consume from all of them by one consumer?

@koderoff koderoff changed the title One cosumer for multiple kafka topics One consumer for multiple kafka topics Apr 27, 2019
@Sevavietl
Copy link

As far as I know, you cannot do this using enqueue.

php-rdkafka (based on librdkafka) on which php-enqueue/rdkafka is based provides low-level consuming for such cases:

$queue = $rk->newQueue();

$topic1 = $rk->newTopic("topic1");
$topic1->consumeQueueStart(0, RD_KAFKA_OFFSET_BEGINNING, $queue);
$topic1->consumeQueueStart(1, RD_KAFKA_OFFSET_BEGINNING, $queue);

$topic2 = $rk->newTopic("topic2");
$topic2->consumeQueueStart(0, RD_KAFKA_OFFSET_BEGINNING, $queue);

while (true) {
    $msg = $queue->consume(1000);
}

Enqueue library implements only high-level consuming.

@Steveb-p
Copy link
Contributor

According to example present in the docs: https://arnaud-lb.github.io/php-rdkafka/phpdoc/rdkafka.examples-high-level-consumer.html it is possible to use multiple topics in high level consumer, so we might look into allowing this in some form or another.

@Sevavietl
Copy link

@Steveb-p nice point, my bad.

From the source code, I see no other problems to implement this in the rdkafka transport except than:

  1. RdKafkaConsumer::getQueue() should return Queue and in the current implementation Queue is the topic itself (RdKafkaTopic).
  2. As transport can be configured with DSN only, as I understand, don't you know if there any conventions for specifying multiple topics there? I have never used this approach myself.

What do you think about mentioned caveats?

Thank you in advance for the answers.

@Steveb-p
Copy link
Contributor

@Sevavietl I wasn't considering what changes to existing code should be made for it to work, or if it even makes sense considering other implementations (of enqueue queues). To be frank, I was almost sure one cannot use multiple topics in high level consumer myself.

As far as 2. is concerned, dsn should be perfectly capable of handling it. Specifically, php-enqueue/dsn can work with arrays like so:
https://github.com/php-enqueue/dsn/blob/5d011c648395307c740d8c0e420f8a9faebce72f/Tests/DsnTest.php#L474-L483

All that would be required is to always treat topic as array and convert single topic into an array if passed.

There might be some more configuration changes that need to be done, I just skimmed through what came to my mind.

@Sevavietl
Copy link

@Steveb-p thank you for the prompt response. I would be glad to help with this functionality, will try to create the PR

@Steveb-p Steveb-p changed the title One consumer for multiple kafka topics [kafka] One consumer for multiple kafka topics Apr 29, 2019
@Steveb-p
Copy link
Contributor

@Sevavietl did you have time to look into this? Or can I take it over?

@Sevavietl
Copy link

@Steveb-p I have looked into, but have not implemented it into PR yet, so if you want you can take it over.
Or, better yet, maybe we can discuss the changes we need to implement this.
I do not know if here is the best place for a long discussion...

@Steveb-p
Copy link
Contributor

@Sevavietl I’m available on php-enqueue’s gitter most od the time :)

@makasim makasim added the pr needed closed bugs or features issues that require a PR. Because there is noone is willig to contribute it label May 21, 2019
@stale
Copy link

stale bot commented Jun 20, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 20, 2019
@Steveb-p
Copy link
Contributor

Hi stale-bot, be quiet please ;)

@stale stale bot removed the wontfix label Jun 20, 2019
@Steveb-p Steveb-p self-assigned this Jul 11, 2019
@stale
Copy link

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 10, 2019
@stale stale bot closed this as completed Aug 17, 2019
@diguin
Copy link

diguin commented Apr 16, 2020

I know I'm a little late for the party, but I just faced the same problem. I noticed that you are able to use a regex as a queue/topic name. You just have to prefix it with ^

@harley84
Copy link

+1, having the ability to subscribe to multiple topics at once would be very helpful

@fmiqbal
Copy link

fmiqbal commented Sep 22, 2022

sry, any update on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pr needed closed bugs or features issues that require a PR. Because there is noone is willig to contribute it wontfix
Projects
None yet
Development

No branches or pull requests

7 participants