static void Main(string[] args) { const string STREAM = "a_test_stream"; const int DEFAULTPORT = 1113; LogManager.Configuration = LoggingConfig.GetDefault(); var queue = new ReadmodelPublisher(); queue.Start(typeof(OrderCreatedEvent).Assembly); _queue = queue; //uncommet to enable verbose logging in client. var settings = ConnectionSettings.Create();//.EnableVerboseLogging().UseConsoleLogger(); using (var conn = EventStoreConnection .Create(settings, new Uri($"tcp://*****:*****@localhost:{DEFAULTPORT}"), "myConn")) { var readModelSubscription = new ReadModelSubscription().SetRetryPolicy(Retries.Fifteen, (i) => TimeSpan.FromMilliseconds(500)); var readModelConsumer = new ReadModelConsumer(conn, queue); conn.ConnectAsync().Wait(); Task.Run(async() => { await readModelConsumer.ConnectToSubscription(readModelSubscription); }); Console.WriteLine("waiting for events. press enter to exit"); Console.ReadLine(); } }
private static IEnumerable <ReadModelSubscription> GetEventsForReadModelSubscribe(Assembly assembly) { var types = assembly.GetTypes(); var readModels = types.Where(ev => ev.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IHandle <>)) && typeof(ReadModelBase).IsAssignableFrom(ev)).ToList(); var subscriptions = new List <ReadModelSubscription>(); foreach (var readModel in readModels) { var instance = Activator.CreateInstance(readModel); var model = instance as ReadModelBase; var createdType = model?.GetsCreatedOn; if (createdType == null) { throw new InvalidReadModelCreationTypeException(readModel.Name); } var propertyTypes = createdType.GetProperties().Select(p => new PropertyType(p.Name, p.PropertyType.Name)); var readModelSubscription = new ReadModelSubscription( readModel.Name, new EventSchema(createdType.Name, propertyTypes)); subscriptions.Add(readModelSubscription); } return(subscriptions); }