[8.x] Ability to specify the broadcaster to use when broadcasting an event #38086
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds an optional attribute on an Event
$broadcasterwhich can be defined per "broadcastable" Event in order to specify which Broadcaster to use when broadcasting the said event.As it stands, once we have configured the default "connection" to use within
config/broadcasting.phpwe cannot use another one for a specific event.This is due to the BroadcastServiceProvider always registering a singleton with a default connection set to
nullwithin the IoC, which means that whenever a new Event which needs to be broadcast is handled, it will resolve theBroadcastercontract from the IoC, always fetching the default broadcaster configured.It could be quite handy to be able to have a bit more flexibility if we were to use a different broadcaster per type of event or type of clients our server-side events should broadcast to.
This is supported by:
InteractsWithBroadcasteradding the definition for the optional attribute as well as a method to set the broadcaster on the fly.In a similar fashion to what we can currently do with queued jobs
we could have the following for basic broadcast events
PendingBroadcastclass in order to specify on the fly which broadcaster to use.connection()there using the optionalbroadcasterattribute. Note that we fallback to the current behaviour which prevents introducing any breaking change.Note: Even though the "connection" term is used throughout the
config/broadcasting.phpfile, I've decided to use "broadcaster" to prevent any confusion with the existing$connectionproperty you can have on a queued event.