Skip to content

[Messenger] Add BatchAsyncHandlerTrait for ParallelMessageBus #60080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from

Conversation

matyo91
Copy link
Contributor

@matyo91 matyo91 commented Mar 28, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #53964 (comment)
License MIT

Key Features

This implementation enables efficient batch processing while taking advantage of the parallel execution capabilities of ParallelMessageBus.

Usage Example

Here's how you would use this trait in a handler class:

class MyParallelBatchHandler
{
    use BatchAsyncHandlerTrait;
    
    public function __construct(ParallelMessageBus $parallelBus)
    {
        $this->setParallelMessageBus($parallelBus);
    }
    
    public function __invoke(MyMessage $message)
    {
        return $this->handle($message, null);
    }
    
    private function process(array $jobs): void
    {
        // This is the fallback implementation that will only be used
        // if ParallelMessageBus is not available/set
        
        // Extract message data
        $data = array_map(fn($job) => $job[0]->getData(), $jobs);
        
        // Perform batch processing
        // ...
        
        // Acknowledge all messages
        foreach ($jobs as [$message, $ack]) {
            $ack->ack();
        }
    }
}

@carsonbot carsonbot added this to the 7.3 milestone Mar 28, 2025
@matyo91 matyo91 force-pushed the messenger-handling-concurrent-messages branch from 97e4cd7 to a571a81 Compare March 28, 2025 22:06
@matyo91 matyo91 force-pushed the messenger-handling-concurrent-messages branch from a571a81 to 29b4e97 Compare March 28, 2025 22:07
@carsonbot carsonbot changed the title Add BatchAsyncHandlerTrait for ParallelMessageBus [Messenger] Add BatchAsyncHandlerTrait for ParallelMessageBus Mar 30, 2025
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants