private static async Task Execute() { var connectionFactory = new EventStoreConnectionFactory("ConnectTo=tcp://127.0.0.1:1113;"); var bus = new EventStoreBus(connectionFactory); var canUnsubscribe = bus.RegisterHandler(new EventSubscriptionRequest <Event>(OnEventReceived, "$ce-hello", lastProcessedEventStreamPosition: null)); var eventStore = new EventStore(connectionFactory, null); var streamName = StreamNameBuilder.BuildStreamName <Hello>(Guid.NewGuid()); await eventStore.CreateNewStream(streamName, new Event[] { new HelloEvent(), }); bool keepContinue = true; while (keepContinue) { switch (Console.ReadKey().Key) { case ConsoleKey.RightArrow: var lastExpectedEventVersion = eventStore.GetStreamLastExpectedEventVersion(streamName); await eventStore.AppendEventsToStream(streamName, new[] { new HelloEvent(), }, lastExpectedEventVersion); break; case ConsoleKey.LeftArrow: keepContinue = false; break; } } }
public async Task ShouldBuildAndRunActors() { var connection = EmbeddedEventStoreConnection.Create(_clusterVNode, _connectionSettings); var connectionMonitor = new EventStoreConnectionStatusMonitor(connection, _loggerFactory); var eventProvider = new ConsumerBasedEventProvider <TestActorAutoBuildOne>(); var eventStoreRepositoryConfiguration = new EventStoreRepositoryConfiguration(); var actorConfiguration = new ActorConfiguration(); var eventStoreRepository = new EventStoreRepository( eventStoreRepositoryConfiguration, connection, connectionMonitor, _loggerFactory); var persistentEventStoreStreamConfiguration = new PersistentSubscriptionEventStoreStreamConfiguration(_streamId, _groupIdOne, _userCredentials); var persistentSubscriptionEventStoreStream = new PersistentSubscriptionEventStoreStream( connectionMonitor, persistentEventStoreStreamConfiguration, eventProvider, _loggerFactory); var volatileEventStoreStreamConfiguration = new SubscribeFromEndEventStoreStreamConfiguration(_userCredentials); var volatileEventStoreStream = new SubscribeFromEndToAllEventStoreStream( connectionMonitor, volatileEventStoreStreamConfiguration, eventProvider, _loggerFactory); await Task.Delay(1000); var eventStoreBus = new EventStoreBus(connectionMonitor, eventStoreRepository); var testActorAutoBuildOne = new TestActorAutoBuildOne(actorConfiguration, _loggerFactory); await testActorAutoBuildOne.ConnectTo(eventStoreBus); var testActorAutoBuildTwo = new TestActorAutoBuildOne(actorConfiguration, _loggerFactory); await testActorAutoBuildTwo.ConnectTo(eventStoreBus); testActorAutoBuildOne.SubscribeToEventStream(persistentSubscriptionEventStoreStream); testActorAutoBuildOne.SubscribeToEventStream(volatileEventStoreStream); await Task.Delay(2000); await testActorAutoBuildTwo.EmitEventStore(new SomeMoreData(_correlationId, "some-stream")); await Task.Delay(1000); Assert.AreEqual(1, testActorAutoBuildOne.Events.Count); await testActorAutoBuildTwo.EmitEventStore(new SomeMoreData(_correlationId, _streamId)); await Task.Delay(100); Assert.AreEqual(3, testActorAutoBuildOne.Events.Count); eventStoreBus.Dispose(); testActorAutoBuildOne.Dispose(); testActorAutoBuildTwo.Dispose(); }