[go: nahoru, domu]

Skip to content
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

Support for event metadata when writing to EventStore #40

Open
jacekzlowocki opened this issue Nov 4, 2020 · 0 comments
Open

Support for event metadata when writing to EventStore #40

jacekzlowocki opened this issue Nov 4, 2020 · 0 comments

Comments

@jacekzlowocki
Copy link

Hi,
I'm using NestJS CQRS architecture with nestjs-eventstore package for emitting event to EventStore and I'm planning to implement a middleware for pub/sub of events to handle things like logging and and setting some default event metadata.

Besides the fact that it's going to be tricky because of lack of support for any kind of events interception when publishing (this is not the subject of this issue, but any ideas are welcome too) there is one more fundamental problem: lack of support for setting event metadata when writing an event to EventStore.

The critical place in the code seems to be EventStoreBus.publish method:

async publish(event: IEvent, stream?: string) {
const payload: EventData = createEventData(
v4(),
event.constructor.name,
true,
Buffer.from(JSON.stringify(event)),
);

which just doesn't support metadata (it would be a fifth argument passed to createEventData)

I would imagine this could be solved by adding another custom field in the event object and using it in EventPublisher, similarly to how currently streamName is handled:

mergeObjectContext<T extends AggregateRoot>(object: T): T {
const eventBus = this.eventBus;
object.publish = (event: IEvent) => {
eventBus.publish(event, (event as IAggregateEvent).streamName);
};
return object;
}

My question is:
do you have plans to implement support for writing event metadata with the event or any experiences with implementing it? Is there anything I should know that I don't see at this point and that is a blocker or a more complex issue?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant