Event Store订阅服务MongoDB
我想知道是否有可能通过Get Event Store
创建订阅服务Mongo
?也许我误解了这句话,但让我解释一下。我目前有一个使用NEventStore
将事件写入Mongo Database
的过程。我想要做的是订阅Stream
Mongo
订阅服务。Event Store订阅服务MongoDB
无法在interweb上找到任何关于此的内容,但这是可能的吗?简而言之,我的问题可能是你可以将两者混合在一起,或者为了做到这一点,我必须将我的活动写入eventstore
而不是Mongo
?也许,我正在谈论这个错误,并且有另一种选择?
我可以看到我正在编写的事件,但无法触发EventAppeared
。所有这些都是在我的机器上进行的。
我试图创建一个精简的应用程序,它做到这一点:
-
使用以下
using (var connection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 1113))) { connection.SubscribeToStreamAsync(@"mongodb://localhost:27017/Test", false, EventAppeared, SubscriptionDropped); var repository = new NEventStoreRepository(); repository.Write(new SomethingHasHappened("Hello")); Console.ReadLine(); } private static void SubscriptionDropped(EventStoreSubscription arg1, SubscriptionDropReason arg2, Exception arg3) { } private static void EventAppeared(EventStoreSubscription arg1, ResolvedEvent arg2) { }
-
我通过NEventStore将事件写入我的蒙戈数据库
创建订阅public void Write(object @event) { var id = Guid.NewGuid(); using (var scope = new TransactionScope()) { using (var store = WireupEventStore()) { using (var stream = store.OpenStream(id.ToString(), 0, int.MaxValue)) { stream.Add(new EventMessage { Body = @event }); stream.CommitChanges(Guid.NewGuid()); scope.Complete(); } } } Console.ReadKey(); } private static IStoreEvents WireupEventStore() { return Wireup .Init() .LogToOutputWindow() .UsingMongoPersistence("NEventStore.MongoDB", new DocumentObjectSerializer()) .InitializeStorageEngine() .UsingJsonSerialization() .Build(); }
事件造成这种情况的正常流动将如下:
(放弃一切已安装并运行...)
- 注册用户在GetEventStore流在 应用程序代码
- 保存事件流
- 的事件出现在你的用户
我认为你要么混淆的东西Ø流试图做一些完全不受支持的事情(比如让MongoDb订阅者访问GetEventStore)。我认为你的代码做的是:
- 设置NEventStore保存到MongoDB的
- 订阅在GetEventStore流称为 “MongoDB的://本地主机:27017 /测试”
- 的保存事件到MongoDb
据我所见,你永远不会保存任何事件给GetEventStore,因此为什么在EventAppeared方法中什么也没有出现。您正在保存到MongoDb。
[更新]
我要订阅的MongoDB流和填充GetEventStore我相信这是不可能的,从我从你的答案收集。
MongoDb没有流,它有集合 - 它是一个文档数据库。流是GetEventStore中的一个概念。但是,它看起来像NEventStore允许你连接一个消息调度程序,这可能意味着你可以注册处理程序来监听事件。在这些处理程序中,您可以保存到GetEventStore。
我相信你已经回答了我的问题。然而,我想订阅一个Mongodb流并填充GetEventStore,我认为这不可能从我的答案中得到。 –
您必须挂钩NEventStore使用的任何机制以允许您订阅事件,然后在您的处理程序中,保存到EventStore:https://github.com/NEventStore/NEventStore-Example/blob/master/NEventStore.Example/MainProgram.cs#L55。 – tomliversidge
干杯的帮助感谢。它觉得我在做什么是错的,但想证实这一点。我有另一种方法,我知道会工作(基本上你在答案中提到的) –
你在说GetEventStore吗? – tomliversidge
道歉,是的。 –
您已将您的mongodb连接作为GetEventStore中事件流的名称。这是故意的吗?您的流实际上是否称为“mongodb:// localhost:27017/Test”? – tomliversidge