refactor(kafka): optimize Producer async processing with type constants#7539
Open
huangdijia wants to merge 8 commits intohyperf:masterfrom
Open
refactor(kafka): optimize Producer async processing with type constants#7539huangdijia wants to merge 8 commits intohyperf:masterfrom
huangdijia wants to merge 8 commits intohyperf:masterfrom
Conversation
- Add SINGLE and BATCH constants for operation type identification - Replace closure-based channel messages with structured arrays [type, args, promise] - Use match expression for cleaner type-based operation dispatch - Simplify error handling and promise management in loop - Improve code readability and maintainability This refactoring maintains the same functionality while making the code more efficient and easier to understand.
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Kafka Producer's async processing implementation to use type constants and structured array messages instead of closures for improved readability and maintainability.
Key Changes
- Introduced
SINGLE = 1andBATCH = 2constants for operation type identification - Replaced closure-based channel messages with structured arrays
[type, args, promise] - Implemented
matchexpression for cleaner operation dispatch based on type constants
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ific InvalidArgumentException
Replaces direct access to $this->chan with a local $chan variable and uses the nullsafe operator to prevent errors if the channel is null. This improves code safety and consistency when handling the channel in Producer methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the Kafka Producer async processing system to improve code readability, maintainability, and efficiency.
Changes Made
SINGLE = 1andBATCH = 2constants for operation type identification[type, args, promise]matchexpression for cleaner type-based operation dispatch instead of closuresBenefits
Backward Compatibility
This is an internal refactoring that maintains the same public API and functionality. No breaking changes are introduced.
Test Plan