Skip to content

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

Merged
taylorotwell merged 2 commits into
laravel:9.xfrom
sethsandaru:9.x--queueable-listener-via-queue-event
Sep 12, 2022
Merged

[9.x] Passing event into viaQueue and viaConnection of Queued Listener#44080
taylorotwell merged 2 commits into
laravel:9.xfrom
sethsandaru:9.x--queueable-listener-via-queue-event

Conversation

@sethsandaru

Copy link
Copy Markdown
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
Copy Markdown
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