public Sample() { Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.Console().CreateLogger(); const string connectionString = "ConnectTo=tcp://admin:changeit@localhost:1113; HeartBeatTimeout=20000; HeartbeatInterval=40000;"; _connection = EventStoreConnection.Create(connectionString, ConnectionSettings.Create()); var repository = new EventStoreSagaRepository <SampleInstance>(_connection); _bus = Bus.Factory.CreateUsingRabbitMq(c => { c.UseSerilog(); c.UseConcurrencyLimit(1); c.PrefetchCount = 1; var host = c.Host(new Uri("rabbitmq://localhost"), h => { h.Username("guest"); h.Password("guest"); }); var machine = new SampleStateMachine(); c.ReceiveEndpoint(host, "essaga_test", ep => ep.StateMachineSaga(machine, repository)); }); }
public Sample() { Log.Logger = new LoggerConfiguration().MinimumLevel.Debug().WriteTo.LiterateConsole().CreateLogger(); var connectionString = ConfigurationManager.ConnectionStrings["eventStore"]; _connection = EventStoreConnection.Create(connectionString.ConnectionString, ConnectionSettings.Create().UseSerilog()); var repository = new EventStoreSagaRepository <SampleInstance>(_connection); _bus = Bus.Factory.CreateUsingRabbitMq(c => { c.UseSerilog(); c.UseConcurrencyLimit(1); c.PrefetchCount = 1; var host = c.Host(new Uri("rabbitmq://localhost"), h => { h.Username("guest"); h.Password("guest"); }); var machine = new SampleStateMachine(); c.ReceiveEndpoint(host, "essaga_test", ep => ep.StateMachineSaga(machine, repository)); }); }
public static void AddMassTransitWithRabbitMq(this IServiceCollection services, IConfiguration appConfig) { if (services == null) { throw new ArgumentNullException("services"); } if (appConfig == null) { throw new ArgumentNullException("appConfig"); } var cfgSection = appConfig.GetSection("RabbitMqHost"); if (!cfgSection.Exists()) { throw new InvalidOperationException("Appsettings: 'RabbitMqHost' section is not found"); } services.Configure <RabbitMqHostOptions>(cfgSection); cfgSection = appConfig.GetSection("AuditStore"); if (!cfgSection.Exists()) { throw new InvalidOperationException("Appsettings: 'AuditStore' section is not found"); } services.Configure <AuditStoreSettings>(cfgSection); services.AddSingleton(svcProv => { var conStr = appConfig.GetConnectionString("EvtStoreConnection"); return(EventStoreConnection.Create(conStr, ConnectionSettings.Create() .UseNetCoreLogger(svcProv.GetService <ILoggerFactory>()) //.EnableVerboseLogging() )); }); services.AddMassTransit(cfg => { cfg.AddSaga <SampleInstance>(); }); services.AddSingleton(svcProv => { var hostOpts = svcProv.GetService <IOptions <RabbitMqHostOptions> >().Value; var machine = new SampleStateMachine(svcProv.GetService <ILogger <SampleStateMachine> >(), appConfig.GetValue("DeleteCompleted", true)); var con = svcProv.GetService <IEventStoreConnection>(); var repository = new EventStoreSagaRepository <SampleInstance>(con); var queueName = appConfig.GetValue("SagaQueueName", "essaga_test"); var bus = Bus.Factory.CreateUsingRabbitMq(cfg => { var host = cfg.CreateHost(hostOpts); cfg.ReceiveEndpoint(host, queueName, e => { e.UseInMemoryOutbox(); e.PrefetchCount = 1; e.UseConcurrencyLimit(1); e.UseRetry(x => { x.Handle <EventStoreSagaConcurrencyException>(); x.Interval(5, TimeSpan.FromMilliseconds(100)); }); e.StateMachineSaga(machine, repository); }); cfg.UseSerilog(); }); var auditSettings = svcProv.GetService <IOptions <AuditStoreSettings> >().Value; if (!string.IsNullOrEmpty(auditSettings?.StreamName)) { var auditStore = new EventStoreMessageAudit(con, auditSettings.StreamName); bus.ConnectSendAuditObservers(auditStore); bus.ConnectConsumeAuditObserver(auditStore); } return(bus); }); }