Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
815c3ab
default queue by class
jackbayliss Nov 19, 2025
e5b1903
rename bits and work on comments
jackbayliss Dec 14, 2025
8bf8cd0
remove alias
jackbayliss Dec 15, 2025
568cdb2
quick adjustment
jackbayliss Dec 15, 2025
b037454
change to route over default
jackbayliss Dec 28, 2025
a95246a
and.. dont forget the tests
jackbayliss Dec 28, 2025
975ac2a
tweak comments
jackbayliss Dec 28, 2025
da07f6f
order provides
jackbayliss Dec 28, 2025
9761c73
test
jackbayliss Dec 28, 2025
4982762
sprinkle some laravel terms
jackbayliss Dec 28, 2025
09b75b4
Revert "sprinkle some laravel terms"
jackbayliss Dec 28, 2025
bf889aa
Reapply "sprinkle some laravel terms"
jackbayliss Dec 28, 2025
0e0dcea
final test tweaks
jackbayliss Dec 28, 2025
acad1e9
Update QueueServiceProvider.php
jackbayliss Dec 29, 2025
142c03a
formatting
taylorotwell Jan 8, 2026
0d31451
fix variable
taylorotwell Jan 8, 2026
badb71e
change this method
jackbayliss Jan 8, 2026
d28e7af
move file / dependency
taylorotwell Jan 8, 2026
812b8f2
Merge branch '13.x-queue-by-class' of github.com:jackbayliss/framewor…
taylorotwell Jan 8, 2026
2ddd154
fix tests
taylorotwell Jan 8, 2026
a8789e5
add support for broadcast events
taylorotwell Jan 8, 2026
1fe92e2
add support for routing connection
taylorotwell Jan 8, 2026
bd666b4
update signature
taylorotwell Jan 8, 2026
d8a42ca
Improve test
jackbayliss Jan 8, 2026
2b39b78
cs
jackbayliss Jan 8, 2026
f5b17f5
Apply resolveConnectionFromQueueRoute
jackbayliss Jan 8, 2026
e0d5383
Update QueueManager.php
jackbayliss Jan 8, 2026
d4ffa21
improve test
jackbayliss Jan 8, 2026
c1de15e
fix le tests
jackbayliss Jan 8, 2026
6a3aff7
and this test..
jackbayliss Jan 8, 2026
5bc5521
more test tweaks and fixes
jackbayliss Jan 8, 2026
3f77dbb
improve tests, add broadcast test
jackbayliss Jan 9, 2026
0f0142e
Add event dispatcher test
jackbayliss Jan 9, 2026
fe9b398
typo
jackbayliss Jan 9, 2026
a7e7e3b
cs
jackbayliss Jan 9, 2026
1a5af26
ensure instance is nulled after
jackbayliss Jan 9, 2026
467cf26
formatting
taylorotwell Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Illuminate/Broadcasting/BroadcastManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Foundation\CachesRoutes;
use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Pusher\Pusher;
Expand All @@ -29,6 +30,8 @@
*/
class BroadcastManager implements FactoryContract
{
use ResolvesQueueRoutes;

/**
* The application instance.
*
Expand Down Expand Up @@ -199,6 +202,10 @@ public function queue($event)
$queue = $event->queue;
}

if (is_null($queue)) {
$queue = $this->resolveQueueFromQueueRoute($event) ?? null;
}

$broadcastEvent = new BroadcastEvent(clone $event);

if ($event instanceof ShouldBeUnique) {
Expand All @@ -210,7 +217,11 @@ public function queue($event)
}

$push = fn () => $this->app->make('queue')
->connection($event->connection ?? null)
->connection(
$event->connection
?? $this->resolveConnectionFromQueueRoute($event)
?? null
)
->pushOn($queue, $broadcastEvent);

$event instanceof ShouldRescue
Expand Down
13 changes: 10 additions & 3 deletions src/Illuminate/Bus/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\Jobs\SyncJob;
use Illuminate\Support\Collection;
use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes;
use RuntimeException;

class Dispatcher implements QueueingDispatcher
{
use ResolvesQueueRoutes;

/**
* The container implementation.
*
Expand Down Expand Up @@ -215,7 +218,9 @@ protected function commandShouldBeQueued($command)
*/
public function dispatchToQueue($command)
{
$connection = $command->connection ?? null;
$connection = $command->connection
?? $this->resolveConnectionFromQueueRoute($command)
?? null;

$queue = ($this->queueResolver)($connection);

Expand All @@ -239,11 +244,13 @@ public function dispatchToQueue($command)
*/
protected function pushCommandToQueue($queue, $command)
{
$queueName = $command->queue ?? $this->resolveQueueFromQueueRoute($command) ?? null;

if (isset($command->delay)) {
return $queue->later($command->delay, $command, queue: $command->queue ?? null);
return $queue->later($command->delay, $command, queue: $queueName);
}

return $queue->push($command, queue: $command->queue ?? null);
return $queue->push($command, queue: $queueName);
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Traits\ReflectsClosures;
Expand All @@ -25,7 +26,7 @@

class Dispatcher implements DispatcherContract
{
use Macroable, ReflectsClosures;
use Macroable, ReflectsClosures, ResolvesQueueRoutes;

/**
* The IoC container instance.
Expand Down Expand Up @@ -647,9 +648,13 @@ protected function queueHandler($class, $method, $arguments)
{
[$listener, $job] = $this->createListenerAndJob($class, $method, $arguments);

$connection = $this->resolveQueue()->connection(method_exists($listener, 'viaConnection')
$connectionName = method_exists($listener, 'viaConnection')
? (isset($arguments[0]) ? $listener->viaConnection($arguments[0]) : $listener->viaConnection())
: $listener->connection ?? null);
: $listener->connection ?? null;

$connection = $this->resolveQueue()->connection(
$connectionName ?? $this->resolveConnectionFromQueueRoute($listener) ?? null
);

$queue = method_exists($listener, 'viaQueue')
? (isset($arguments[0]) ? $listener->viaQueue($arguments[0]) : $listener->viaQueue())
Expand All @@ -659,6 +664,10 @@ protected function queueHandler($class, $method, $arguments)
? (isset($arguments[0]) ? $listener->withDelay($arguments[0]) : $listener->withDelay())
: $listener->delay ?? null;

if (is_null($queue)) {
$queue = $this->resolveQueueFromQueueRoute($listener) ?? null;
}

is_null($delay)
? $connection->pushOn(enum_value($queue), $job)
: $connection->laterOn(enum_value($queue), $delay, $job);
Expand Down
24 changes: 22 additions & 2 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,17 @@ public function queue(Queue $queue)

$connection = property_exists($this, 'connection') ? $this->connection : null;

$queueName = property_exists($this, 'queue') ? $this->queue : null;
if (is_null($connection) && method_exists($queue, 'resolveConnectionFromQueueRoute')) {
$connection = $queue->resolveConnectionFromQueueRoute($this);
}

$queueName = property_exists($this, 'queue')
? $this->queue
: null;

if (is_null($queueName) && method_exists($queue, 'resolveQueueFromQueueRoute')) {
$queueName = $queue->resolveQueueFromQueueRoute($this);
}

return $queue->connection($connection)->pushOn(
$queueName ?: null, $this->newQueuedJob()
Expand All @@ -248,7 +258,17 @@ public function later($delay, Queue $queue)
{
$connection = property_exists($this, 'connection') ? $this->connection : null;

$queueName = property_exists($this, 'queue') ? $this->queue : null;
$queueName = property_exists($this, 'queue')
? $this->queue
: null;

if (is_null($connection) && method_exists($queue, 'resolveConnectionFromQueueRoute')) {
$connection = $queue->resolveConnectionFromQueueRoute($this);
}

if (is_null($queueName) && method_exists($queue, 'resolveQueueFromQueueRoute')) {
$queueName = $queue->resolveQueueFromQueueRoute($this);
}

return $queue->connection($connection)->laterOn(
$queueName ?: null, $delay, $this->newQueuedJob()
Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Notifications/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Illuminate\Contracts\Notifications\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Notifications\Factory as FactoryContract;
use Illuminate\Support\Manager;
use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes;
use InvalidArgumentException;

class ChannelManager extends Manager implements DispatcherContract, FactoryContract
{
use ResolvesQueueRoutes;

/**
* The default channel used to deliver messages.
*
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Notifications/NotificationSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ protected function queueNotification($notifiables, $notification)
$notification->locale = $this->locale;
}

$connection = $notification->connection;
$connection = $notification->connection
?? $this->manager->resolveConnectionFromQueueRoute($notification)
?? null;

if (method_exists($notification, 'viaConnections')) {
$connection = $notification->viaConnections()[$channel] ?? $connection;
}

$queue = $notification->queue;
$queue = $notification->queue
?? $this->manager->resolveQueueFromQueueRoute($notification)
?? null;

if (method_exists($notification, 'viaQueues')) {
$queue = $notification->viaQueues()[$channel] ?? $queue;
Expand Down
16 changes: 16 additions & 0 deletions src/Illuminate/Queue/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
use Closure;
use Illuminate\Contracts\Queue\Factory as FactoryContract;
use Illuminate\Contracts\Queue\Monitor as MonitorContract;
use Illuminate\Support\Queue\Concerns\ResolvesQueueRoutes;
use InvalidArgumentException;

/**
* @mixin \Illuminate\Contracts\Queue\Queue
*/
class QueueManager implements FactoryContract, MonitorContract
{
use ResolvesQueueRoutes;

/**
* The application instance.
*
Expand Down Expand Up @@ -120,6 +123,19 @@ public function stopping($callback)
$this->app['events']->listen(Events\WorkerStopping::class, $callback);
}

/**
* Set the queue route for the given class.
*
* @param array|class-string $class
Copy link
Contributor

Choose a reason for hiding this comment

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

You can type the array as well:

Suggested change
* @param array|class-string $class
* @param array<class-string, string|array{0: string, 1: string}>|class-string $class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll let Big T decide on that one 👍🏻

* @param string|null $queue
* @param string|null $connection
* @return void
*/
public function route(array|string $class, $queue = null, $connection = null)
{
$this->queueRoutes()->set($class, $queue, $connection);
}

/**
* Determine if the driver is connected.
*
Expand Down
106 changes: 106 additions & 0 deletions src/Illuminate/Queue/QueueRoutes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

namespace Illuminate\Queue;

class QueueRoutes
{
/**
* The mapping of class names to their default routes.
*
* @var array<class-string, string>
*/
protected $routes = [];

/**
* Get the queue connection that a given queueable instance should be routed to.
*
* @param object $queueable
* @return string|null
*/
public function getConnection($queueable)
{
$route = $this->getRoute($queueable);

if (is_null($route)) {
return;
}

return is_string($route)
? $route
: $route[0];
}

/**
* Get the queue that a given queueable instance should be routed to.
*
* @param object $queueable
* @return string|null
*/
public function getQueue($queueable)
{
$route = $this->getRoute($queueable);

if (is_null($route)) {
return;
}

return is_string($route)
? $route
: $route[1];
}

/**
* Get the queue that a given queueable instance should be routed to.
*
* @param object $queueable
* @return string|null
*/
public function getRoute($queueable)
{
if (empty($this->routes)) {
return null;
}

$classes = array_merge(
[get_class($queueable)],
class_parents($queueable) ?: [],
class_implements($queueable) ?: [],
class_uses_recursive($queueable)
);

foreach ($classes as $class) {
if (isset($this->routes[$class])) {
return $this->routes[$class];
}
}

return null;
}

/**
* Register the queue route for the given class.
*
* @param array|class-string $class
* @param string|null $queue
* @param string|null $connection
* @return void
*/
public function set(array|string $class, $queue = null, $connection = null)
{
$routes = is_array($class) ? $class : [$class => [$connection, $queue]];

foreach ($routes as $from => $to) {
$this->routes[$from] = $to;
}
}

/**
* Get all registered queue routes.
*
* @return array
*/
public function all()
{
return $this->routes;
}
}
14 changes: 14 additions & 0 deletions src/Illuminate/Queue/QueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function register()
$this->registerConnection();
$this->registerWorker();
$this->registerListener();
$this->registerRoutes();
$this->registerFailedJobServices();
}

Expand Down Expand Up @@ -288,6 +289,18 @@ protected function registerListener()
});
}

/**
* Register the default queue routes binding.
*
* @return void
*/
protected function registerRoutes()
{
$this->app->singleton('queue.routes', function () {
return new QueueRoutes;
});
}

/**
* Register the failed job services.
*
Expand Down Expand Up @@ -388,6 +401,7 @@ public function provides()
'queue.connection',
'queue.failer',
'queue.listener',
'queue.routes',
'queue.worker',
];
}
Expand Down
Loading
Loading