Skip to content
This repository was archived by the owner on Jun 10, 2022. It is now read-only.
13 changes: 8 additions & 5 deletions src/Producer/SyncProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,15 @@ protected function convertMessage($data)

$topicMeta = $topicInfos[$value['topic']];
$partNums = array_keys($topicMeta);
shuffle($partNums);
$partId = 0;
if (! isset($value['partId']) || ! isset($topicMeta[$value['partId']])) {
$partId = $partNums[0];
if (isset($value['key']) && trim($value['key'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracting this logic to a method and using early returns will make things way easier to understand, could you please do that?

$partId = crc32($value['key']) % count($partNums);
} else {
$partId = $value['partId'];
shuffle($partNums);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the shuffle needed only for when you're using $partsNum?

if (! isset($value['partId']) || ! isset($topicMeta[$value['partId']])) {
$partId = $partNums[0];
} else {
$partId = $value['partId'];
}
}

$brokerId = $topicMeta[$partId];
Expand Down