Skip to content

Conversation

@wuxi889
Copy link
Contributor

@wuxi889 wuxi889 commented Jul 30, 2025

Changed

This PR introduces support for configuring retry behavior in the Kafka producer by adding two new options:

  • produce.max_retries: Number of times to retry sending a message if it initially fails.
  • produce.retry_delay: Time to wait (in seconds) between each retry attempt.

These values are injected into the producer via two new setter methods:

  • setProduceRetry(int $times)
  • setProduceRetrySleep(float $seconds)

Comment on lines 31 to 34
'produce' => [
'max_retries' => 3,
'retry_delay' => 0.1,
],
Copy link
Member

Choose a reason for hiding this comment

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

展开成 producer_max_retriesproducer_retry_delay 会不会更好?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果展开的话可以用 produce_max_retriesproduce_retry_delay 或者 produce_retry produce_retry_sleep。 因为 swoole/kafka 内部设置重试时调用的是 setProduceRetry 与 setProduceRetrySleep。

参考之前 producer_epoch 的设置对应的调用方法是 setProducerEpoch

可以到后面再考虑把通用、生产者、消费者配置区分开的,毕竟 kafka 可配置的参数很多,都在同一层级的话会比较乱。

Copy link
Member

Choose a reason for hiding this comment

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

现在混着用更乱

Copy link
Contributor Author

@wuxi889 wuxi889 Jul 31, 2025

Choose a reason for hiding this comment

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

我调整成 produce_retry ,produce_retry_sleep

@wuxi889 wuxi889 requested a review from huangdijia July 31, 2025 07:29
Comment on lines +31 to +32
'produce_retry' => 3,
'produce_retry_sleep' => 0.1,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'produce_retry' => 3,
'produce_retry_sleep' => 0.1,
'producer_retry' => 3,
'producer_retry_sleep' => 0.1,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

用 producer 不太合理,retry 是作用在生产动作上的,swoole/kafka 对应的调用方法是 setProduceRetryproducer_id 这种是对生产者对象进行设置,所以对应的是 setProducerId

image

@wuxi889 wuxi889 requested a review from huangdijia July 31, 2025 10:09
@limingxinleo limingxinleo changed the title Add retry configuration for Kafka producer Added config produce_retry and producer_retry_sleep for kafka. Aug 2, 2025
@limingxinleo limingxinleo merged commit 031414b into hyperf:master Aug 2, 2025
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants