-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.3] Allow Broadcasting a notification now instead on queue #16867
[5.3] Allow Broadcasting a notification now instead on queue #16867
Conversation
@@ -44,6 +51,10 @@ public function __construct($notifiable, $notification, $data) | |||
$this->data = $data; | |||
$this->notifiable = $notifiable; | |||
$this->notification = $notification; | |||
|
|||
if (method_exists($this->notification, 'broadcastNow')) { | |||
$this->connection = $this->notification->broadcastNow() ? 'sync' : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why should we assume the sync connection is called "sync". We can name it whatever we want? It's only the driver which is "sync", not the connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we assume the sync driver is called sync
in multiple areas in the framework already, for example: https://github.com/laravel/framework/blob/5.3/src/Illuminate/Broadcasting/BroadcastManager.php#L107
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a bit of a bug tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to re-think the queue config in 5.4, and have a default "queue queue", and a default "sync queue"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good solution to me.
Is there no way we can use the |
I think it might be a little cleaner to have a |
In real usage I think it would look something like: return new BroadcastMessage($this->toArray())->now(); |
And then the BroadcastChannel would properly handle that message type in getData. |
Tweaked this to just use Queueable trait. |
This is probably worth mentioning in the docs. |
This is an attempt to allow broadcasting notifications immediately instead of doing it via queue, to achieve this you'll need to add the following method in your Notification class:
This will have the
BroadcastNotificationCreated
$connection set tosync
so that the queue manager use it as the connection name.Update
Added a new
BroadcastMessage
that can be returned fromtoBroadcast
, this new class has anow()
method that we use to update the connection name.