Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the Event Store Client API (.NET), how to I write to a stream and link one event to another?

I have set up Event Store, and can happily write events to the stream, subscribe, and read historical events, that all works fine.

I can see that in the ResolvedEvent that gets passed to my subscription handler method has a Link property, but I'm wondering how, when I write to the stream, do I 'set' this property?

I've tried setting various meta data properties (using JSON notation), looking through the source code, but didn't find anything that works.

It is possible that I'm going about this the wrong way, and what I'm trying to do (write an event to a stream, and then link a second event to the first so I can find the 'reply' later on) should be done another way.

like image 452
Vitani Avatar asked Mar 05 '23 23:03

Vitani


1 Answers

I do not think that Link is what you think it means? (unless you can quote something from a documentation that is what it is in fact supposed to do)

That Link is used for Projections that are created from various other streams.

For example:

When you enable all the projections in EvenStore you will get a Group projection that runs out of the box. This projection works by grouping streams by a naming conventions of "group-id"

Think of saving several aggregates to their own streams

  • customer-10001
  • customer-10002
  • customer-10003

That is great, but how do you then subscribe to any events that happens to any of those stream. This is where the build in group projection comes to work

You subscribe to the $ce-customer stream, which is a projection.

When you actually read that projection all you will get is the link to the original event. This is the LINK that I am talking about and maybe you confusing with.

So you know that option in the .NET client resolveLinkTos

 Task<EventReadResult> ReadEventAsync(string stream, long eventNumber, bool resolveLinkTos);

If you set that to true on resolveLinkTos then the original events will come back in the stream data (not just the links to the original events).

So it will return all the data from all the linked streams.

like image 176
Piotr Kula Avatar answered Apr 08 '23 11:04

Piotr Kula