static void Main(string[] args) { var METRIC_STREAM = Config.MetricStream; var AGG_STREAM = Config.SecondaryStream; var service = new EventStoreService(Config.IpAddress, Config.DefaultPort); var streamSub = service.SubscribeToStream(METRIC_STREAM, (s, @event) => { var data = Utility.BytesToString(@event.Event.Data); Console.WriteLine($"Received: {@event.Event.EventStreamId}. Event Number: {@event.Event.EventNumber}"); var message = JsonConvert.DeserializeObject<CompletedMessage>(data); Console.WriteLine($"Completed Message Created on: {message.Date.ToShortTimeString()}"); }); var subStreamSub = service.SubscribeToStream(AGG_STREAM, (s, @event) => { var data = Utility.BytesToString(@event.Event.Data); Console.WriteLine( $"Received Secondary Event: {@event.Event.EventStreamId}. Event Number: {@event.Event.EventNumber}"); var message = JsonConvert.DeserializeObject<CompletedMessage>(data); Console.WriteLine($"Completed Message Created on: {message.Date.ToShortTimeString()}"); }); Console.WriteLine("Waiting for events. Hit enter to exit"); Console.ReadKey(); }
public RoutesController(EventStoreService eventStore, CacheDatabaseManager db, IEnumerable <IDomainIndex> indices) { _eventStore = eventStore; _db = db; _mediaIndex = indices.OfType <MediaIndex>().First(); _entityIndex = indices.OfType <EntityIndex>().First(); _referencesIndex = indices.OfType <ReferencesIndex>().First(); _ratingIndex = indices.OfType <RatingIndex>().First(); }
public TagsController(EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache) { _eventStore = eventStore; _db = db; _entityIndex = cache.Index <EntityIndex>(); _mediaIndex = cache.Index <MediaIndex>(); _tagIndex = cache.Index <TagIndex>(); _referencesIndex = cache.Index <ReferencesIndex>(); }
public DriverController( EventStoreService eventStoreService, ReadModelService readModelService, MessengerService messengerService) { this.eventStoreService = eventStoreService; this.readModelService = readModelService; this.messengerService = messengerService; }
public UsersController(EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache, IOptions <EndpointConfig> endpointConfig, ILogger <UsersController> logger) { _eventStore = eventStore; _db = db; _entityIndex = cache.Index <EntityIndex>(); _userIndex = cache.Index <UserIndex>(); _endpointConfig = endpointConfig.Value; _logger = logger; }
public MediaController(EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache, IOptions <UploadFilesConfig> uploadConfig, IOptions <EndpointConfig> endpointConfig, ILogger <MediaController> logger) { _logger = logger; _eventStore = eventStore; _db = db; _entityIndex = cache.Index <EntityIndex>(); _mediaIndex = cache.Index <MediaIndex>(); _referencesIndex = cache.Index <ReferencesIndex>(); _uploadConfig = uploadConfig.Value; _endpointConfig = endpointConfig.Value; }
/// <summary> /// Creates an entity by appending a <see cref="CreatedEvent"/> and the necessary /// <see cref="PropertyChangedEvent"/>s to the event stream. /// </summary> /// <typeparam name="T">Type of the entity</typeparam> /// <param name="service">EventStoreService</param> /// <param name="obj">Object which contains the values</param> /// <param name="resourceType">Resource type of the object</param> /// <param name="id">Id of the object</param> /// <param name="userId">Id of the user</param> /// <returns></returns> public static async Task CreateEntityAsync <T>(EventStoreService service, T obj, ResourceType resourceType, int id, string userId) where T : new() { if (obj == null) { throw new ArgumentException("The object to store cannot be null", nameof(obj)); } var emptyObject = Activator.CreateInstance <T>(); var createdEvent = new CreatedEvent(resourceType.Name, id, userId); await service.AppendEventAsync(createdEvent); await UpdateEntityAsync(service, emptyObject, obj, resourceType, id, userId); }
public CacheDatabaseManager( EventStoreService eventStore, IMongoDbContext db) { // For now, the cache database is always created from scratch by replaying all events. // This also implies that, for now, the cache database always contains the entire data (not a subset). // In order to receive all the events, a Catch-Up Subscription is created. _db = db; // 2) Subscribe to EventStore to receive all past and future events _eventStore = eventStore; _eventStore.EventStream.SubscribeCatchUp(ApplyEvent); }
public ExhibitPagesController( IOptions <ExhibitPagesConfig> exhibitPagesConfig, EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache) { _exhibitPagesConfig = exhibitPagesConfig; _eventStore = eventStore; _db = db; _mediaIndex = cache.Index <MediaIndex>(); _entityIndex = cache.Index <EntityIndex>(); _referencesIndex = cache.Index <ReferencesIndex>(); _exhibitPageIndex = cache.Index <ExhibitPageIndex>(); }
//write events from here static void Main(string[] args) { const string textMessageStream = "text-message"; var service = new EventStoreService(Config.IpAddress, Config.DefaultPort); var people = new List<string> {"jim", "mike", "susie"}; //simulate already subscribed. This information would come from the actual message in the form of it not being the first //phase transition or something else that tells us that this is not the first message related to an individuals var alreadySubscribed = new List<string>(); var count = 0; using (service) { while (true) { count++; var person = people[count%3]; var model = BuildTextMessage(person); var metadata = new Metadata { ClassVersion = 1 }; var subStream = $"{textMessageStream}-{person}"; if (alreadySubscribed.Contains(person) == false) { service.SubscribeToStream(subStream, (s, @event) => { var metaData = service.GetStreamMetaData<Counter>(subStream); var textMessage = JsonConvert.DeserializeObject<TextMessageSent>(Utility.BytesToString(@event.Event.Data)); Console.WriteLine($"Substream text message received for stream: {subStream}. Data {textMessage.Sender} - {textMessage.Message}"); Console.WriteLine($"Count is {metaData.Count}"); metaData.Count++; service.SetMetaData(subStream, metaData); }); alreadySubscribed.Add(person); } service.WriteToStreamAsync(textMessageStream, "messageSend", model, metadata); service.WriteToStreamAsync(subStream, "messageSend", model, metadata); Thread.Sleep(1000); } } }
public CacheDatabaseManager( EventStoreService eventStore, IOptions <EndpointConfig> config, ILogger <CacheDatabaseManager> logger) { // For now, the cache database is always created from scratch by replaying all events. // This also implies that, for now, the cache database always contains the entire data (not a subset). // In order to receive all the events, a Catch-Up Subscription is created. // 1) Open MongoDB connection and clear existing database var mongo = new MongoClient(config.Value.MongoDbHost); mongo.DropDatabase(config.Value.MongoDbName); _db = mongo.GetDatabase(config.Value.MongoDbName); var uri = new Uri(config.Value.MongoDbHost); logger.LogInformation($"Connected to MongoDB cache database on '{uri.Host}', using database '{config.Value.MongoDbName}'"); // 2) Subscribe to EventStore to receive all past and future events _eventStore = eventStore; _eventStore.EventStream.SubscribeCatchUp(ApplyEvent); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Use an in-memory database for quick dev services.AddDbContext <AppDbContext>(opt => opt.UseInMemoryDatabase(databaseName: "AppDb")); services.AddControllers(); var esConnection = EventStoreConnection.Create( Configuration["EventStore:connectionString"], ConnectionSettings.Create().KeepReconnecting(), "asd"); var store = new EventStoreService(esConnection); services.AddSingleton(esConnection); services.AddSingleton <IEventStoreService>(store); services.AddScoped <IProductRepository, ProductRepository>(); services.AddScoped <IProductService, ProductService>(); services.AddSingleton <IHostedService, HostedService>(); services.AddSwaggerGen(c => { c.SwaggerDoc( "v1", new Microsoft.OpenApi.Models.OpenApiInfo { Title = "Products", Version = "v1" }); }); }
public ScoreBoardController(EventStoreService ev, CacheDatabaseManager db, InMemoryCache cache) { _eventStore = ev; _db = db; _board = cache.Index <ScoreBoardIndex>(); }
public HistoryController(EventStoreService eventStore, InMemoryCache cache) { _eventStore = eventStore; _entityIndex = cache.Index <EntityIndex>(); }
public ExhibitVisitedController(EventStoreService eventStore, InMemoryCache cache, DataStoreService dataStoreService, CacheDatabaseManager db) : base(eventStore, cache) { _index = cache.Index <ExhibitsVisitedIndex>(); _dataStoreService = dataStoreService; _db = db; }
/// <summary> /// Deletes an entity by appendeing a <see cref="DeletedEvent"/> to the event stream. /// </summary> /// <param name="service">EventStoreService</param> /// <param name="resourceType">Resource type</param> /// <param name="id">Id of the entity</param> /// <param name="userId">Id of the user</param> /// <returns></returns> public static async Task DeleteEntityAsync(EventStoreService service, ResourceType resourceType, int id, string userId) { await service.AppendEventAsync(new DeletedEvent(resourceType.Name, id, userId)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); var esConnection = EventStoreConfiguration.ConfigureEsConnection( Configuration["EventStore:ConnectionString"], Environment.ApplicationName); // services.AddSingleton<IEventStoreConnection>(esConnection); IEventSerdes eventSerdes = new ContextEventSchema(); IEventStorage storage = new EventStorage(esConnection, eventSerdes); var stories = Stories.OfUseCases( new CustomerUseCases(new Repository <Customer.State>(storage)) ); services.AddSingleton(stories); var documentStore = RavendbDocumentStoreFactory.CreateDocStore( Configuration["RavenDb:Server"], Configuration["RavenDb:Database"] ); var customerViewModelWriter = new RaventDbAtomicWriter <string, CustomerViewModel>(documentStore); services.AddSingleton <IAtomicWriter <string, CustomerViewModel> >(customerViewModelWriter); services.AddSingleton(new CustomerEventListener(customerViewModelWriter)); services.AddSingleton <IListenTo <CustomerRegistered> >(x => x.GetService <CustomerEventListener>()); services.AddSingleton <IListenTo <CustomerRegistered> >(x => x.GetService <CustomerEventListener>()); services.AddSingleton <IListenTo <CustomerRelocated> >(x => x.GetService <CustomerEventListener>()); services.AddSingleton <IListenTo <CustomerContactInfoChanged> >(x => x.GetService <CustomerEventListener>()); var subscriptionIntegrator = new SubscriptionIntegrator( esConnection , new EsCheckpointStore(esConnection, "process-checkpoint") , "processMessenger" // , new ProcessMessenger( // new ProcessOf<SampleProcessState>( // new SampleStateRepository() // , stories // ) // ) //or: // , new ProcessMessenger( // new SampleProcess( // new SampleStateRepository() // , stories // ) // ) //or: , MessageBroadcaster <EventEnvelope> .Subscribe( services.BuildServiceProvider() , m => m.Payload) , eventSerdes ); var eventStoreService = new EventStoreService( esConnection, subscriptionIntegrator); services.AddSingleton <IHostedService>(eventStoreService); services.AddSingleton <IQueryReader <CustomerViewModel> >(new RavenDbQueryReader <CustomerViewModel>(documentStore)); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
/// <summary> /// Updates an entity by appending <see cref="PropertyChangedEvent"/>s to the event stream. /// Uses <see cref="CompareEntities{T}(T, T, ResourceType, int, string)"/> to compare the entities. /// </summary> /// <typeparam name="T">Type of the entitiy</typeparam> /// <param name="service">EventStoreService</param> /// <param name="oldObject">Old object</param> /// <param name="newObject">New object</param> /// <param name="resourceType">Resource type</param> /// <param name="id">Id of the entity</param> /// <param name="userId">Id of the user</param> /// <returns></returns> public static async Task UpdateEntityAsync <T>(EventStoreService service, T oldObject, T newObject, ResourceType resourceType, int id, string userId) { var events = CompareEntities(oldObject, newObject, resourceType, id, userId); await service.AppendEventsAsync(events); }
public FooController(EventStoreService eventStore, CacheDatabaseManager db, InMemoryCache cache) { _eventStore = eventStore; _db = db; _entityIndex = cache.Index <EntityIndex>(); }
public StudentDetailsController(EventStoreService eventStore, InMemoryCache cache) { _eventStore = eventStore; _userIndex = cache.Index <UserIndex>(); }
static void Main() { EventStoreService.Start().WaitForExit(); }
public PackageController(EventStoreService eventStoreService, MessengerService messengerService) { this.eventStoreService = eventStoreService; this.messengerService = messengerService; }