public static IStreak <T> ReplicateTo <T>(this IStreak <T> source, IStreak <T> destination, int chunk = 1) { Task.Factory.StartNew(() => { while (true) { try { var count = 0; var batch = new List <T>(chunk); foreach (var e in source.Get(from: destination.Length + 1, to: long.MaxValue, continuous: true)) { batch.Add(e); count++; if (count % chunk == 0) { destination.Save(batch); batch.Clear(); } } } catch (Exception ex) { Debug.WriteLine($"Replication failed (retrying in a second): {ex}"); Thread.Sleep(1000); } } }, TaskCreationOptions.LongRunning); return(source); }
public void Setup() { writer = new global::Streak.Core.Streak(Environment.CurrentDirectory, writer: true); var input = new List <Event> { new Event { Type = "Test.Event.A", Data = "Tick: 1", Meta = "CorrelationId: 1" }, new Event { Type = "Test.Event.B", Data = "Tick: 2", Meta = "CorrelationId: 2" }, new Event { Type = "Test.Event.C", Data = "Tick: 3", Meta = "CorrelationId: 3" }, new Event { Type = "Test.Event.D", Data = "Tick: 4", Meta = "CorrelationId: 4" }, new Event { Type = "Test.Event.E", Data = "Tick: 5", Meta = "CorrelationId: 5" } }; writer.Save(input); reader = new global::Streak.Core.Streak(Environment.CurrentDirectory); output = reader.Get(@from: 2, to: 4).ToList(); }