我想知道是否可以通过创建订阅Mongo
服务Get Event Store
?也许我的措辞不正确,但让我解释一下。我目前有一个将事件写入Mongo Database
using的过程NEventStore
。我想做的是有一个订阅服务,它订阅一个Stream
in Mongo
。
无法在互联网上找到任何关于此的信息,但这可能吗?简而言之,我的问题也许是您可以将两者混合并匹配在一起,还是为了做到这一点,我必须将我的事件写到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 将事件写入我的 mongo 数据库
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(); }