public static IEventFlowOptions UseStreamsDbEventStore( this IEventFlowOptions eventFlowOptions, string connectionString, string service) { StreamsDBClient client = null; using (var a = AsyncHelper.Wait) { a.Run(StreamsDBClient.Connect(connectionString), c => client = c); } return(eventFlowOptions .RegisterServices(f => { f.Register(r => client, Lifetime.Singleton); f.Register <NullReadModelLocator, NullReadModelLocator>(); // todo: move to own extension method //f.Register<IStreamsDbMessageFactory, StreamsDbMessageFactory>(Lifetime.Singleton); //f.Register<IStreamsDbPublisher, StreamsDbPublisher>(Lifetime.Singleton); //f.Register<ISubscribeSynchronousToAll, StreamsDbDomainEventPublisher>(); // f.Register(rc => new StreamsDbServiceConfiguration(service), Lifetime.Singleton); }) //.AddMetadataProvider<ServiceMetadataProvider>() .UseEventStore <StreamsDbEventPersistence>()); }
static async Task Main(string[] args) { var client = await StreamsDBClient.Connect(); var db = client.DB(); // read from stdin and write to stream var input = Task.Run(async() => { Console.WriteLine("enter a message an press [enter]"); while (true) { try { var line = Console.ReadLine(); await db.AppendStream("chat", new MessageInput { Type = "string", Value = Encoding.UTF8.GetBytes(line) }); } catch (Exception e) { Console.WriteLine("append failed: " + e.Message); } } }); // subscribe to stream and print messages var read = Task.Run(async() => { try { await using var subscription = db.SubscribeStream("chat", -1); while (await subscription.MoveNextAsync()) { var message = subscription.Current; var text = Encoding.UTF8.GetString(message.Value); Console.WriteLine("received: " + text); } } catch (Exception e) { Console.WriteLine("read error: " + e); } }); Task.WaitAny(input, read); }
public static IEventFlowOptions UseStreamsDbEventStore( this IEventFlowOptions eventFlowOptions, string connectionString) { StreamsDBClient client = null; using (var a = AsyncHelper.Wait) { a.Run(StreamsDBClient.Connect(connectionString), c => client = c); } return(eventFlowOptions .RegisterServices(f => f.Register(r => client, Lifetime.Singleton)) .UseEventStore <StreamsDbEventPersistence>()); }