Skip to content

Conversation

@huangdijia
Copy link
Contributor

@huangdijia huangdijia commented Nov 15, 2025

Summary

This PR standardizes the parameter naming in the AsyncQueue and Kafka facades to use $pool instead of $queue, which more accurately reflects that these parameters specify connection pools rather than queue names.

Changes

  • AsyncQueue facade (src/facade/src/AsyncQueue.php:29):

    • Renamed parameter from $queue to $pool in push() method
    • Added @property null|string $pool annotation for better IDE support
    • Updated logic to check both $pool and $queue properties for backward compatibility
    • Pool precedence: explicit $pool parameter → job's $queue property → job's $pool property → 'default'
  • Kafka facade (src/facade/src/Kafka.php:24, src/facade/src/Kafka.php:33):

    • Renamed parameter from $queue to $pool in send() and sendBatch() methods
    • Used $subPool for clarity in batch message grouping logic
    • Consistent fallback order: explicit $pool → message's $pool property → message's $queue property → 'default'

Benefits

  1. Semantic clarity: Parameter names now accurately reflect their purpose (selecting a connection pool)
  2. Backward compatibility: Both facades still check for the legacy $queue property on jobs/messages
  3. Consistency: Both facades now follow the same naming convention and fallback logic
  4. Maintainability: Clearer code makes future modifications easier

Test plan

  • Verify existing tests pass
  • Confirm AsyncQueue jobs can still be dispatched to different pools
  • Confirm Kafka messages can be sent to different producer pools
  • Test backward compatibility with jobs/messages that have $queue property set
  • Validate that the fallback to 'default' pool works as expected

Summary by CodeRabbit

发布说明

  • Refactor(重构)
    • 异步队列和消息服务的接口参数进行了调整,以支持更灵活的资源池管理机制,提升了系统的可扩展性和配置灵活性。

- Rename parameter from $queue to $pool in AsyncQueue::push() and Kafka facade methods to accurately reflect that these parameters specify connection pools, not queue names
- Update AsyncQueue to check both $pool and $queue properties for backward compatibility, with $pool taking precedence
- Add @Property annotation for $pool in AsyncQueue docblock
- Ensure consistent fallback logic across both facades with 'default' as final fallback
- Improve code clarity by using $pool for pool selection and $subPool for batch message grouping in Kafka::sendBatch()

This change improves API consistency and makes the codebase more maintainable by using semantically correct parameter names.
@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2025

Warning

Rate limit exceeded

@huangdijia has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 23 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e518e99 and b6b4f49.

📒 Files selected for processing (5)
  • src/facade/composer.json (1 hunks)
  • src/facade/src/AMQP.php (1 hunks)
  • src/facade/src/AsyncQueue.php (1 hunks)
  • src/facade/src/Kafka.php (1 hunks)
  • src/facade/src/Log.php (1 hunks)

概览

AsyncQueue 门面类将 push 方法的参数从 $queue 重命名为 $pool,并添加了 $pool 属性注解。Kafka 门面类则将 sendsendBatch 方法的参数从 $pool 改为 $queue,并调整了内部默认解析和消息路由逻辑。

变更清单

功能模块/文件 变更摘要
异步队列参数重命名
src/facade/src/AsyncQueue.php
push 方法的第三参数从 ?string $queue 改为 ?string $pool;添加 @property null|string $pool 属性注解;更新内部池选择逻辑,使用计算后的 pool 值进行队列查找
Kafka 方法签名调整
src/facade/src/Kafka.php
sendsendBatch 方法的第二参数从 ?string $pool 改为 ?string $queue;调整内部默认值解析链(使用 queue 而非 pool);更新消息分组和生产者路由逻辑以适配新参数

预期审查工作量

🎯 2 (简单) | ⏱️ ~8 分钟

需额外关注的方面:

  • AsyncQueue 和 Kafka 这两个文件在参数命名上的不一致方向(一个改为 pool,一个改为 queue),需验证这是否为预期设计或是否存在协调问题
  • Kafka.php 中内部默认值解析链的具体实现细节,确保兼容性和向后兼容性

可能相关的 PR

诗句

队列与卡夫卡齐欢唱,🐰
池的名字换新装,
参数重调逻辑详,
消息路由更顺畅!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确反映了主要变更——将AsyncQueue和Kafka facades中的参数命名从$queue标准化为$pool,这与PR的核心目标完全一致。

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/facade/src/Kafka.php (1)

18-21: 缺少 @Property 注解

与 AsyncQueue facade(src/facade/src/AsyncQueue.php:21)不同,Kafka facade 没有添加 @property null|string $pool 注解。为了保持一致性并提供更好的 IDE 支持,建议添加此注解。

应用此 diff:

 /**
  * @mixin ProducerManager
  * @property null|string $queue
+ * @property null|string $pool
  */
 class Kafka extends Facade
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1fefda and e518e99.

📒 Files selected for processing (2)
  • src/facade/src/AsyncQueue.php (1 hunks)
  • src/facade/src/Kafka.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/facade/src/AsyncQueue.php (1)
src/facade/src/Facade.php (1)
  • Facade (18-82)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.2
  • GitHub Check: Test on PHP 8.2 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.1 with Swoole 6.1.2
  • GitHub Check: Test on PHP 8.1 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.2 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 5.1.8
  • GitHub Check: Test on PHP 8.3 with Swoole 6.0.2
  • GitHub Check: Test on PHP 8.2 with Swoole 6.1.2
  • GitHub Check: Test on PHP 8.3 with Swoole 6.1.2
🔇 Additional comments (3)
src/facade/src/AsyncQueue.php (2)

21-21: 良好的 IDE 支持改进

添加 @property null|string $pool 注解有助于 IDE 自动补全和类型推断。


33-33: 使用解析后的 pool 值正确

假设属性解析顺序问题得到解决,此处的实现是正确的。

src/facade/src/Kafka.php (1)

33-45: 批量发送逻辑实现正确

sendBatch() 方法正确地按 pool 对消息进行分组,并为每个 pool 调用相应的生产者。$subPool 的引入提高了代码清晰度,避免了变量名称混淆。

Comment on lines +24 to +27
public static function send(ProduceMessage $produceMessage, ?string $pool = null): void
{
$queue = (fn ($queue) => $this->queue ?? $queue)->call($produceMessage, $queue);
self::getProducer($queue)->sendBatch([$produceMessage]);
$pool ??= (fn () => $this->pool ?? $this->queue ?? 'default')->call($produceMessage);
self::getProducer($pool)->sendBatch([$produceMessage]);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

属性检查顺序更合理,但与 AsyncQueue 不一致

Kafka 的属性检查顺序($this->pool ?? $this->queue)优先检查新的 $pool 属性,这对于标准化工作来说更合理。然而,AsyncQueue(src/facade/src/AsyncQueue.php:31)使用了相反的顺序($this->queue ?? $this->pool),这会造成两个 facade 之间的不一致。

建议统一两个 facade 的属性检查顺序以提高代码库的一致性。参见对 AsyncQueue.php 的评审意见。

🤖 Prompt for AI Agents
In src/facade/src/Kafka.php around lines 24-27 there is an inconsistency in the
property fallback order compared to AsyncQueue (src/facade/src/AsyncQueue.php
line 31): Kafka uses ($this->pool ?? $this->queue) while AsyncQueue uses
($this->queue ?? $this->pool). Make the facades consistent by changing the Kafka
fallback to the same order used in AsyncQueue (use $this->queue ?? $this->pool
when resolving the default pool/queue) or, alternatively, update both files to
the chosen canonical order; ensure both files use the identical fallback
expression and run tests to confirm no behavior regression.

@huangdijia huangdijia merged commit 28e87af into main Nov 15, 2025
3 checks passed
@huangdijia huangdijia deleted the fix/facade-pool-parameter-consistency branch November 15, 2025 14:15
huangdijia added a commit that referenced this pull request Nov 15, 2025
#1010)

* fix: standardize pool parameter naming in AsyncQueue and Kafka facades

- Rename parameter from $queue to $pool in AsyncQueue::push() and Kafka facade methods to accurately reflect that these parameters specify connection pools, not queue names
- Update AsyncQueue to check both $pool and $queue properties for backward compatibility, with $pool taking precedence
- Add @Property annotation for $pool in AsyncQueue docblock
- Ensure consistent fallback logic across both facades with 'default' as final fallback
- Improve code clarity by using $pool for pool selection and $subPool for batch message grouping in Kafka::sendBatch()

This change improves API consistency and makes the codebase more maintainable by using semantically correct parameter names.

* fix: add dispatch methods to AMQP, AsyncQueue, and Kafka facades

* fix: remove unnecessary suggestion for friendsofhyperf/support in composer.json

* fix: standardize parameter naming in Log facade channel method

---------

Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
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.

2 participants