使用事件存储客户端API(.NET),如何写入流并将一个事件链接到另一个事件? [英] Using the Event Store Client API (.NET), how to I write to a stream and link one event to another?

查看:94
本文介绍了使用事件存储客户端API(.NET),如何写入流并将一个事件链接到另一个事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了事件存储,并且可以愉快地将事件写入流,订阅和读取历史事件,一切正常.

我可以看到在传递给我的订阅处理程序方法的ResolvedEvent中具有Link属性,但是我想知道在写入流时如何设置"该属性?/p>

我尝试通过源代码来设置各种元数据属性(使用JSON表示法),但没有找到任何有效的方法.

我可能会以错误的方式进行操作,以及尝试做的事情(将事件写入流,然后将第二个事件链接到第一个事件,这样我就可以找到回复"稍后)应该以另一种方式完成.

解决方案

我不认为Link是您认为的意思? (除非您可以引用文档中实际上应做的事情)

该链接用于从其他各种流创建的投影.

例如:

当在EvenStore中启用所有投影时,您将获得一个开箱即用的组"投影.此投影通过按"group-id"的命名约定对流进行分组来工作

请考虑将多个聚合保存到自己的流中

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

那太好了,但是您如何订阅那些流中发生的任何事件.这是内置的组投影开始起作用的地方

您订阅了$ ce-customer流,这是一个预测.

当您实际阅读该投影时,您所获得的只是原始事件的链接.这是我正在谈论的 LINK ,也许您对此感到困惑.

所以您知道.NET客户端resolveLinkTos

中的该选项

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

如果在resolveLinkTos上将其设置为true,则原始事件将重新出现在流数据中(而不仅仅是原始事件的链接).

因此它将返回所有链接流中的所有数据.

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.

解决方案

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.

这篇关于使用事件存储客户端API(.NET),如何写入流并将一个事件链接到另一个事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆