Skip to content

Add event emitter for subscriptions#864

Merged
DavidBadura merged 7 commits into
4.0.xfrom
feature/subscription-event-emitter
Jun 16, 2026
Merged

Add event emitter for subscriptions#864
DavidBadura merged 7 commits into
4.0.xfrom
feature/subscription-event-emitter

Conversation

@DavidBadura

@DavidBadura DavidBadura commented Jun 16, 2026

Copy link
Copy Markdown
Member

Subscribers can emit events back into the store. If a subscribe method type-hints an EventEmitter, it gets injected and the subscriber can emit() events into its own subscription_<id> stream, or linkTo() an explicit stream. Another subscription can then subscribe to those events. Typical use case: a projection finishes updating and emits an event that a notification subscriber reacts to.

Emitting only happens during run by default; while booting the emitter is a noop so a replay doesn't duplicate events. #[OverrideEventEmitting(true)] also emits during boot, false suppresses it entirely.

When a subscription is removed the handlers dispatch OnSubscriptionRemoved. Registering the RemoveSubscriptionStreamListener on the event dispatcher removes the corresponding subscription_<id> stream from the store.

Subscribers can now emit events back into the store by type-hinting an
EventEmitter argument on a subscribe method. Emitted events go into a
dedicated subscription_<id> stream by default, or an explicit stream via
linkTo, so other subscriptions can react to them.

By default events are only emitted during run; while booting the emitter is
a noop to avoid duplicates on replay. This can be overridden per subscriber
with the OverrideEventEmitting attribute. When a subscription is removed an
OnSubscriptionRemoved event is dispatched; registering the
RemoveSubscriptionStreamListener removes the subscription stream from the
store.

ArgumentResolver::resolve() now receives an ArgumentResolverContext (message,
subscription and subscriber metadata) instead of just the message. See
UPGRADE-4.0.
The default stream name (subscription_<id>) is now built directly in the
EventEmitterResolver and the RemoveSubscriptionStreamListener. Also rename the
DefaultEventEmitter property to defaultStream.
@DavidBadura DavidBadura requested a review from DanielBadura June 16, 2026 08:58
@DavidBadura DavidBadura added this to the 4.0.0 milestone Jun 16, 2026
@DavidBadura DavidBadura added the enhancement New feature or request label Jun 16, 2026

@DanielBadura DanielBadura left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM besides naming stuff, but we need some more unit tests as even the non-diff mutation test is failing

Comment thread src/Attribute/OverrideEventEmitting.php Outdated
Comment thread src/Subscription/Subscriber/EventEmitter/DefaultEventEmitter.php Outdated
Replace the OverrideEventEmitting(bool) attribute with two dedicated marker
attributes: EnableEventEmittingDuringBoot (also emit while booting) and
DisableEventEmitting (never emit). The subscriber metadata now carries two
booleans instead of a nullable one.
The handler tests now record dispatched OnSubscriptionRemoved events and assert
them for every removal path (and assert none on the teardown error/no-removal
paths). The resolver test now emits through the resolved emitter and asserts the
subscription_<id> target stream, instead of only checking the returned type.
Add a MessageProcessorTest that drives a real subscribe method through the
processor (covers the previously uncovered foreach), assert StoreEventEmitter
does not touch the store for empty event lists (mock instead of in-memory, to
kill the return-removal mutant), and add a two-subscription teardown test so the
continue after a cleanup error is not equivalent to a break. Also assert the
SubscriberMetadata event-emitting defaults.
@DavidBadura DavidBadura requested a review from DanielBadura June 16, 2026 10:14
@DavidBadura DavidBadura merged commit d0845aa into 4.0.x Jun 16, 2026
35 of 38 checks passed
@DavidBadura DavidBadura deleted the feature/subscription-event-emitter branch June 16, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants