Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.

Key is not used for partitionning #228

Closed
mantzas opened this issue Jul 23, 2018 · 6 comments
Closed

Key is not used for partitionning #228

mantzas opened this issue Jul 23, 2018 · 6 comments

Comments

@mantzas
Copy link

mantzas commented Jul 23, 2018

I have added the 'key' to the payload, which is the ID of one of my entities, so that i get the same entity in the same partition. Our topic has 4 partitions. Unfortunately it does not seem to work.
We expect that with the above the message will always go in one of the 4 partitions, but we have seen that the message will be send to all partitions.
Do you have any idea with this is the case?

@lcobucci
Copy link
Contributor

@mantzas can you please check if #218 fulfils your needs?

@mantzas
Copy link
Author

mantzas commented Jul 23, 2018

@lcobucci is this not already implemented in the library?

@lcobucci
Copy link
Contributor

@mantzas nope, that's why I'm asking you to check that particular branch. I'll be reviewing it further this week to integrate, but will be only available in v3.x

@mantzas
Copy link
Author

mantzas commented Jul 23, 2018

@lcobucci yes, this is what's needed from our side. We integrated the current code in our codebase to make this work now. We will wait until v3 to get the library then. Thanks man

@demyanovs
Copy link

demyanovs commented Jul 27, 2018

@mantzas @lcobucci
Currently, in order not to change this client and wait for the merge #218, you can get information directly from the broker and proceed as follows:

$broker = \Kafka\Broker::getInstance();
$topic_infos = $broker->getTopics();
$topic_meta = $topic_infos[$topic_title];
$part_nums = array_keys($topic_meta);
if ($key) {
    $part_id = $part_nums[crc32($key) % count($part_nums)];
} else {
    shuffle($part_nums);
    $part_id = $part_nums[0];
}

And then set partId

$producer->send([
    [
        'topic' => $topic_title,
        'value' => $message,
        'partId' => $part_id,
    ],
]);

@mantzas
Copy link
Author

mantzas commented Jul 27, 2018

@demyanovs done this already based on #218. it's running in production already. thanks.

@mantzas mantzas closed this as completed Jul 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants