public void Dulicate_message_is_detected() { var builder = new CqrsEngineBuilder(); builder.Memory(m => { m.AddMemorySender("in", s => s.IdGenerator(() => "same")); m.AddMemoryRouter("in", c => "memory:null"); }); var observer = new ImmediateEventsObserver(); builder.Advanced.RegisterObserver(observer); using (var token = new CancellationTokenSource()) using (var build = builder.Build()) { var sender = build.Resolve<IMessageSender>(); sender.SendOne(new Message()); sender.SendOne(new Message()); observer.Event += @event => { var e = @event as EnvelopeDuplicateDiscarded; if (e != null) { token.Cancel(); } }; build.Start(token.Token); token.Token.WaitHandle.WaitOne(10000); Assert.IsTrue(token.IsCancellationRequested); } }
public void Dulicate_message_is_detected() { var builder = new CqrsEngineBuilder(); builder.Memory(m => { m.AddMemorySender("in", s => s.IdGenerator(() => "same")); m.AddMemoryRouter("in", c => "memory:null"); }); var observer = new ImmediateEventsObserver(); builder.Advanced.RegisterObserver(observer); using (var token = new CancellationTokenSource()) using (var build = builder.Build()) { var sender = build.Resolve <IMessageSender>(); sender.SendOne(new Message()); sender.SendOne(new Message()); observer.Event += @event => { var e = @event as EnvelopeDuplicateDiscarded; if (e != null) { token.Cancel(); } }; build.Start(token.Token); token.Token.WaitHandle.WaitOne(10000); Assert.IsTrue(token.IsCancellationRequested); } }
public static CqrsEngineBuilder Configure(FileStorageConfig cache) { var observer = new ImmediateEventsObserver(); observer.Event += @event => { var failed = @event as EnvelopeDispatchFailed; if (failed != null) { Trace.WriteLine(failed.Exception); } }; var builder = new CqrsEngineBuilder(); builder.Advanced.RegisterObserver(observer); builder.Advanced.RegisterQueueWriterFactory(context => new FileQueueWriterFactory(cache, context.Resolve <IEnvelopeStreamer>())); builder.Domain(m => { m.HandlerSample <IConsume <IBaseMessage> >(c => c.Consume(null)); m.InAssemblyOf <StoryViewHandler>(); m.InAssemblyOf <AddNote>(); m.InAssemblyOf <StoryList>(); }); builder.Advanced.CustomDataSerializer(t => new DataSerializerWithProtoBuf(t)); builder.Advanced.CustomEnvelopeSerializer(new EnvelopeSerializerWithProtoBuf()); builder.Storage(c => { RegisterAtomicStorage(cache, c); c.TapeIsInFiles(Path.Combine(cache.Folder.FullName, "tapes")); }); builder.File(m => { m.AddFileSender(cache, "router", cm => cm.IdGeneratorForTests()); m.AddFileProcess(cache, "router", x => x.DispatcherIsLambda(SaveAndRoute)); m.AddFileProcess(cache, "events", p => p.DispatchAsEvents(md => md.WhereMessagesAre <IEvent>())); m.AddFileProcess(cache, "aggregates", p => p.DispatcherIs(context => { var readers = context.Resolve <ITapeStorageFactory>(); var streamer = context.Resolve <IEnvelopeStreamer>(); var reg = context.Resolve <QueueWriterRegistry>(); return(new AggregateDispatcher(readers, streamer, "files:router", reg)); })); }); return(builder); }