问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/50906995/using-the-event-store-client-api-net-how-to-i-write-to-a-stream-and-link-one