/// <summary> /// Configures the system to use SQL-backed command scheduling. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns>The updated configuration.</returns> public static Configuration UseSqlCommandScheduling( this Configuration configuration, Action <ReadModelCatchup <CommandSchedulerDbContext> > configureCatchup = null) { var container = configuration.Container; var scheduler = container.Resolve <SqlCommandScheduler>(); var subscription = container.Resolve <IEventBus>().Subscribe(scheduler); configuration.RegisterForDisposal(subscription); container.RegisterSingle(c => scheduler); if (configureCatchup != null) { var catchup = new ReadModelCatchup <CommandSchedulerDbContext>(scheduler) { CreateReadModelDbContext = scheduler.CreateCommandSchedulerDbContext, }; configureCatchup(catchup); catchup.PollEventStore(); container.RegisterSingle(c => catchup); configuration.RegisterForDisposal(catchup); } return(configuration); }
/// <summary> /// Polls the event store and passes events to <see cref="ReadModelCatchup{TDbContext}.Run" /> when new events are found. /// </summary> /// <typeparam name="TDbContext">The type of the database context used to access the read models.</typeparam> /// <param name="readModelCatchup">The read model catchup instance to run.</param> /// <param name="interval">The interval at which polling occurs.</param> /// <param name="scheduler">The scheduler on which work is scheduled.</param> public static ReadModelCatchup <TDbContext> PollEventStore <TDbContext>( this ReadModelCatchup <TDbContext> readModelCatchup, TimeSpan?interval = null, IScheduler scheduler = null) where TDbContext : DbContext { interval = interval ?? TimeSpan.FromSeconds(5); scheduler = scheduler ?? Scheduler.Default; return(readModelCatchup.PollEventStore(Observable.Interval(interval.Value, scheduler).Select(_ => Unit.Default))); }
/// <summary> /// Configures the system to use SQL-backed command scheduling. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns>The updated configuration.</returns> public static Configuration UseSqlCommandScheduling( this Configuration configuration, Action <ReadModelCatchup <CommandSchedulerDbContext> > configureCatchup = null) { var container = configuration.Container; container.AddFallbackToDefaultClock(); var scheduler = new SqlCommandScheduler( configuration, container.Resolve <Func <CommandSchedulerDbContext> >(), container.Resolve <GetClockName>()); if (container.All(r => r.Key != typeof(SqlCommandScheduler))) { container.Register(c => scheduler) .Register <ISchedulerClockTrigger>(c => scheduler) .Register <ISchedulerClockRepository>(c => scheduler); } var subscription = container.Resolve <IEventBus>().Subscribe(scheduler); configuration.RegisterForDisposal(subscription); container.RegisterSingle(c => scheduler); if (configureCatchup != null) { var catchup = new ReadModelCatchup <CommandSchedulerDbContext>(scheduler) { CreateReadModelDbContext = scheduler.CreateCommandSchedulerDbContext }; configureCatchup(catchup); catchup.PollEventStore(); container.RegisterSingle(c => catchup); configuration.RegisterForDisposal(catchup); } configuration.IsUsingSqlCommandScheduling(true); return(configuration); }