/// <summary>
        /// Instantiate a replay command publisher used
        /// </summary>
        public ReplayCommandPublisher(IMicroserviceReplayHost host, ICommandPublisher commandPublisher, ILoggerFactory loggerFactory = null)
        {
            loggerFactory ??= new NullLoggerFactory();

            Host             = host;
            CommandPublisher = commandPublisher;
            Logger           = loggerFactory.CreateLogger <ReplayCommandPublisher>();
        }
Esempio n. 2
0
        /// <summary>
        /// Entrypoint
        /// </summary>
        static void Main(string[] args)
        {
            /**
             * Logging is important, so first set up a logger factory
             */
            using var loggerFactory = LoggerFactory.Create(configure =>
            {
                configure.AddConsole().SetMinimumLevel(LogLevel.Information);
            });

            /**
             * Set up a context using environment variables
             */
            using var context = new RabbitMqContextBuilder()
                                .ReadFromEnvironmentVariables()
                                .CreateContext();

            /**
             * Build a host using the loggerfactory, context and register any event listeners in the package.
             */
            using var hostBuilder = new MicroserviceReplayHostBuilder()
                                    .SetLoggerFactory(loggerFactory)
                                    .WithBusContext(context)
                                    .UseConventions();

            /**
             * Now create the host and start it
             */
            using IMicroserviceReplayHost host = (MicroserviceReplayHost)hostBuilder.CreateHost();
            host.Start();

            /**
             * Start spamming events to the auditlogger as a demonstration
             */
            StartSpammingEvents(context);

            /**
             * Now let's start replaying, first create a replay command
             */
            Guid processId = Guid.NewGuid();
            ReplayEventsCommand replayEventsCommand = new ReplayEventsCommand(DateTime.Now.ToFileTimeUtc(), processId)
            {
                Types = new List <string> {
                    "AnimalAddedEvent"
                }
            };

            /**
             * Create the publishers
             */
            ICommandPublisher       publisher = new CommandPublisher(context);
            IReplayCommandPublisher replayCommandPublisher = new ReplayCommandPublisher(host, publisher, loggerFactory);

            /**
             * Commence a replay!
             */
            replayCommandPublisher.Initiate(replayEventsCommand);
        }