Add event emitter for subscriptions#864
Merged
Merged
Conversation
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.
DanielBadura
left a comment
Member
There was a problem hiding this comment.
LGTM besides naming stuff, but we need some more unit tests as even the non-diff mutation test is failing
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.
DanielBadura
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Subscribers can emit events back into the store. If a subscribe method type-hints an
EventEmitter, it gets injected and the subscriber canemit()events into its ownsubscription_<id>stream, orlinkTo()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
runby default; while booting the emitter is a noop so a replay doesn't duplicate events.#[OverrideEventEmitting(true)]also emits during boot,falsesuppresses it entirely.When a subscription is removed the handlers dispatch
OnSubscriptionRemoved. Registering theRemoveSubscriptionStreamListeneron the event dispatcher removes the correspondingsubscription_<id>stream from the store.