Skip to content
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

[9.x] Passing event into viaQueue and viaConnection of Queued Listener #44080

Merged
merged 2 commits into from
Sep 12, 2022
Merged

[9.x] Passing event into viaQueue and viaConnection of Queued Listener #44080

merged 2 commits into from
Sep 12, 2022

Conversation

sethsandaru
Copy link
Contributor

Proposal this (if got approved & merged, I'll submit a doc PR)

For our project, we have a lot of Queued Listeners. At the moment, for some critical endpoints (that need to respond as fast as they can), we need to push it to a redis connection instead of sqs based on the events's data (which is impossible at the moment)

At my first try (which didn't work), I used the shouldQueue($event) to set the $connection dynamically.

After spending a bit of time reading the logic. I see that before Laravel invoking the shouldQueue, it will create a new concrete listener class to and use it to check.

And before the queue push happen, Laravel create another new concrete listener class via Reflector. Thus my $connection will never be there.

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Events/Dispatcher.php#L560

With this patch, we would be able to do something like this:

public function viaConnection($event): string
{
    if ($event->useRedisQueue) {
        return 'redis';
    } 

    return config('queue.default');
}

Code & unit testing added, no breaking changes!

@sethsandaru
Copy link
Contributor Author

Hi @taylorotwell @driesvints could you please review to see if this one makes sense?

Thanks

@sethsandaru sethsandaru changed the title [9.x][Patch] Passing the argument into viaQueue and viaConnection of Queued Listener [9.x][Patch] Passing event into viaQueue and viaConnection of Queued Listener Sep 11, 2022
@driesvints driesvints changed the title [9.x][Patch] Passing event into viaQueue and viaConnection of Queued Listener [9.x] Passing event into viaQueue and viaConnection of Queued Listener Sep 12, 2022
@taylorotwell taylorotwell merged commit bb7e7dd into laravel:9.x Sep 12, 2022
taylorotwell pushed a commit that referenced this pull request Sep 15, 2022
* extract via connection

* extract via queue

* fix call
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