protected override void SetUp() { _activator = Using(new BuiltinHandlerActivator()); _waitedSeconds = new ConcurrentQueue<double>(); _rebusConfigurer = Configure.With(_activator) .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "test backoff")) .Options(o => { o.SetBackoffTimes(TimeSpan.FromSeconds(0.2), TimeSpan.FromSeconds(0.5), TimeSpan.FromSeconds(1)); o.Decorate<ITransport>(c => { var transport = c.Get<ITransport>(); var transportTap = new TransportTap(transport); transportTap.NoMessageReceived += () => { var elapsedSinceStart = DateTime.UtcNow - _busStartTime; var elapsedSeconds = Math.Round(elapsedSinceStart.TotalSeconds, 1); _waitedSeconds.Enqueue(elapsedSeconds); }; return transportTap; }); o.SetMaxParallelism(10); o.SetNumberOfWorkers(1); }); }
/// <summary> /// Configures Rebus to use an outbox. /// This will store a (message ID, source queue) tuple for all processed messages, and under this tuple any messages sent/published will /// also be stored, thus enabling truly idempotent message processing. /// </summary> public static RebusConfigurer Outbox(this RebusConfigurer configurer, Action <StandardConfigurer <IOutboxStorage> > configure) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } configurer.Options(o => { configure(StandardConfigurer <IOutboxStorage> .GetConfigurerFrom(o)); // if no outbox storage was registered, no further calls must have been made... that's ok, so we just bail out here if (!o.Has <IOutboxStorage>()) { return; } o.Decorate <ITransport>(c => new OutboxClientTransportDecorator(c.Get <ITransport>(), c.Get <IOutboxStorage>())); o.Register(c => { var asyncTaskFactory = c.Get <IAsyncTaskFactory>(); var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var outboxStorage = c.Get <IOutboxStorage>(); var transport = c.Get <ITransport>(); return(new OutboxForwarder(asyncTaskFactory, rebusLoggerFactory, outboxStorage, transport)); }); o.Decorate(c => { _ = c.Get <OutboxForwarder>(); return(c.Get <Options>()); }); o.Decorate <IPipeline>(c => { var pipeline = c.Get <IPipeline>(); var outboxConnectionProvider = c.Get <IOutboxConnectionProvider>(); var step = new OutboxIncomingStep(outboxConnectionProvider); return(new PipelineStepInjector(pipeline) .OnReceive(step, PipelineRelativePosition.After, typeof(SimpleRetryStrategyStep))); }); }); return(configurer); }
private static RebusConfigurer ConfigureRebus(RebusConfigurer c, IConfigurationRoot config) { var connectionString = config.GetValue <string>("ConnectionString"); //var sqlOptions = new SqlServerTransportOptions(connectionString); return(c.Logging(x => x.ColoredConsole()) .Routing(x => x.TypeBased().Map <StartSaga>("ServiceBus")) .Options(x => x.SimpleRetryStrategy("Error")) .Transport(x => x .UseSqlServerAsOneWayClient(connectionString) ) .Subscriptions(x => x.StoreInSqlServer(connectionString, "Subscriptions", isCentralized: true, automaticallyCreateTables: false))); }
public static RebusConfigurer ConfigureEndpoint(this RebusConfigurer configurer, EndpointRole role) { configurer .Logging(l => l.Serilog(Log.Logger)) .Transport(t => { if (role == EndpointRole.Client) { t.UseMsmqAsOneWayClient(); } else { t.UseMsmq(Config.AppSetting("QueueName")); } }) .Subscriptions(s => { var subscriptionsTableName = Config.AppSetting("SubscriptionsTableName"); s.StoreInSqlServer("RebusDatabase", subscriptionsTableName, isCentralized: true); }) .Sagas(s => { if (role != EndpointRole.SagaHost) { return; } var dataTableName = Config.AppSetting("SagaDataTableName"); var indexTableName = Config.AppSetting("SagaIndexTableName"); // store sagas in SQL Server to make them persistent and survive restarts s.StoreInSqlServer("RebusDatabase", dataTableName, indexTableName); }) .Timeouts(t => { if (role == EndpointRole.Client) { return; } var tableName = Config.AppSetting("TimeoutsTableName"); // store timeouts in SQL Server to make them persistent and survive restarts t.StoreInSqlServer("RebusDatabase", tableName); }); return(configurer); }
private void configureRabbtMQServerTransport(RebusConfigurer configurer) { var sqlConnectionString = _configuration.GetConnectionString("RebusSql"); var rabbitConnectionString = _configuration.GetConnectionString("RebusRabbit"); configurer.Transport(t => t.UseRabbitMq(rabbitConnectionString, _thisBus.ToString())) .Sagas(x => { x.StoreInSqlServer( connectionString: sqlConnectionString, dataTableName: "rbs.Rebus_Sagas", indexTableName: "rbs.Rebus_SagasIndex"); }); }
private RebusConfigurer ConfigureRebus(RebusConfigurer rebusConfigurer, BusConfig busConfig) { _services.AutoRegisterHandlersFromAssemblyOf <MyHandler>(); rebusConfigurer.Routing(x => x.TypeBased() .MapAssemblyOf <MyMessage>(busConfig.MainQueue) ); rebusConfigurer.Transport(configurer => configurer.UseInMemoryTransport(new InMemNetwork(), busConfig.MainQueue)); rebusConfigurer.Subscriptions(configurer => configurer.StoreInMemory()); rebusConfigurer.Sagas(standardConfigurer => standardConfigurer.StoreInMemory()); return(rebusConfigurer); }
/// <summary> /// Configures rebus to use the filesystem store for everything in one-way client mode. /// </summary> /// <param name="configurer">The rebus configuration</param> /// <param name="baseDirectory">The directory to store everything under</param> public static RebusConfigurer UseFileSystemAsOneWayClient(this RebusConfigurer configurer, string baseDirectory) { var transport = Path.Combine(baseDirectory, "transport"); var timeouts = Path.Combine(baseDirectory, "timeouts"); var subscriptions = Path.Combine(baseDirectory, "subscriptions.json"); var dataBus = Path.Combine(baseDirectory, "databus"); return(configurer .Transport(t => t.UseFileSystemAsOneWayClient(transport)) .Subscriptions(t => t.UseJsonFile(subscriptions)) .Timeouts(t => t.UseFileSystem(timeouts)) .Options(o => { o.EnableDataBus().StoreInFileSystem(dataBus); })); }
protected override void SetUp() { var connectionInfo = AmazonSqsTransportFactory.ConnectionInfo; var accessKeyId = connectionInfo.AccessKeyId; var secretAccessKey = connectionInfo.SecretAccessKey; var amazonSqsConfig = new AmazonSQSConfig { RegionEndpoint = connectionInfo.RegionEndpoint }; var queueName = TestConfig.GetName("defertest"); AmazonSqsManyMessagesTransportFactory.PurgeQueue(queueName); _activator = Using(new BuiltinHandlerActivator()); _configurer = Configure.With(_activator).Transport(t => t.UseAmazonSnsAndSqs(amazonSqsConfig: amazonSqsConfig, workerQueueAddress: queueName)).Options(o => o.LogPipeline()); }
void IInitializable <IWindsorContainer> .Initialized(IWindsorContainer container) { container.Register( Component.For <IBus>() .UsingFactoryMethod(() => { RebusConfigurer rebus = Configure.With(new CastleWindsorContainerAdapter(container)); if (BusConfiguration != null) { rebus = BusConfiguration(rebus, container.Kernel); } // This will start Rebus - allowing one single instance of Rebus for this application. return(rebus.Start()); })); }
public static RebusConfigurer EnablePerMessageRunningTimeReporting(this RebusConfigurer configurer, TimeSpan threshold) { configurer.Events(e => { e.MessageContextEstablished += (_, ctx) => { var sw = new System.Diagnostics.Stopwatch(); ctx.Items[StopwatchKey] = sw; ctx.Disposed += sw.Stop; sw.Start(); }; e.AfterMessage += (_, ex, msg) => { if (!MessageContext.HasCurrent) { _Log.Warn("Missing message context at AfterMessage event?!"); return; } var ctx = MessageContext.GetCurrent(); var tname = ctx.CurrentMessage?.GetType().Name; var sw = ctx.Items.GetValueOrDefault(StopwatchKey, null) as System.Diagnostics.Stopwatch; if (sw == null) { _Log.Warn("Missing stopwatch at AfterMessage event?!"); return; } if (sw.Elapsed > threshold) { _Log.WarnFormat("Message processing took too long ({0}), for message of type '{1}' (threshold: {2})", sw.Elapsed, tname, threshold); } else { _Log.InfoFormat("Message processing took ({0}), for message of type '{1}'", sw.Elapsed, tname); } }; }); return(configurer); }
/// <summary> /// Configures Rebus to use a full Azure storage-based setup with storage queues as transport, table storage /// for subscriptions, and a combined table storage- and blob-based saga storage. /// Optionally enables the data bus (using blob storage) and saga snapshots (using blob storage too) /// </summary> public static RebusConfigurer UseAzure(this RebusConfigurer configurer, string storageAccountConnectionStringOrName, string inputQueueAddress) { if (configurer == null) { throw new ArgumentNullException(nameof(configurer)); } if (storageAccountConnectionStringOrName == null) { throw new ArgumentNullException(nameof(storageAccountConnectionStringOrName)); } if (inputQueueAddress == null) { throw new ArgumentNullException(nameof(inputQueueAddress)); } var storageAccount = AzureConfigurationHelper.GetStorageAccount(storageAccountConnectionStringOrName); return(Configure(configurer, storageAccount, inputQueueAddress)); }
/// <summary> /// Configures Rebus to encrypt messages. /// </summary> public static void EnableJsonEncryption(this RebusConfigurer configurer, EncryptionFactory encryptionFactory, EncryptStateBuilder encryptStateBuilder, DecryptStateBuilder decryptStateBuilder) { configurer.Options(options => { options.Decorate <IPipeline>( resolutionContext => { var pipeline = resolutionContext.Get <IPipeline>(); var injector = new PipelineStepInjector(pipeline); var decryptStep = new DecryptStep(encryptionFactory, decryptStateBuilder); injector.OnReceive(decryptStep, PipelineRelativePosition.Before, typeof(DeserializeIncomingMessageStep)); var encryptStep = new EncryptStep(encryptionFactory, encryptStateBuilder); injector.OnSend(encryptStep, PipelineRelativePosition.Before, typeof(SerializeOutgoingMessageStep)); return(injector); }); }); }
private void configureSqlServerTransport(RebusConfigurer configurer) { var connectionString = _configuration.GetConnectionString("RebusSql"); configurer.Transport(t => t.UseSqlServer( transportOptions: new SqlServerTransportOptions( connectionString: connectionString, enlistInAmbientTransaction: false ), getInputQueueName(_thisBus))) .Subscriptions(x => x.StoreInSqlServer( connectionString: connectionString, tableName: "rbs.Rebus_Subscriptions", isCentralized: true)) .Sagas(x => { x.StoreInSqlServer( connectionString: connectionString, dataTableName: "rbs.Rebus_Sagas", indexTableName: "rbs.Rebus_SagasIndex"); }); }
private RebusConfigurer ConfigureRebus(RebusConfigurer c, IConfigurationRoot config) { var connectionString = config.GetValue <string>("ConnectionString"); //var sqlOptions = new SqlServerTransportOptions(connectionString); return(c .Logging(x => { x.Serilog(); }) .Options(x => { x.SimpleRetryStrategy("Error"); x.EnableMessageAuditing("Audit"); x.SetNumberOfWorkers(10); x.SetMaxParallelism(10); }) .Transport(x => x .UseSqlServer(connectionString, "ServiceBus") ) .Subscriptions(x => x.StoreInSqlServer(connectionString, "Subscriptions", isCentralized: true, automaticallyCreateTables: false)) .Sagas(x => x.StoreInSqlServer(connectionString, "Sagas", "SagaIndexes"))); }
public static RebusConfigurer SetTimeToBeReceivedFrom <TAttribute>(this RebusConfigurer configurer, Func <TAttribute, TimeSpan> getter) where TAttribute : System.Attribute { Guard.IsNotNull(() => configurer, configurer); Guard.IsNotNull(() => getter, getter); return(configurer.Events(e => { e.MessageSent += (advbus, destination, message) => { var attribute = message.GetType() .GetCustomAttributes(typeof(TAttribute), false) .Cast <TAttribute>() .SingleOrDefault(); if (attribute != null) { advbus.AttachHeader(message, Headers.TimeToBeReceived, getter(attribute).ToString()); } }; })); }
public static RebusConfigurer ValidateIncomingMessages(this RebusConfigurer configurer, IEnumerable <Type> inclusions = null, IEnumerable <Type> exclusions = null) { configurer.Events(evs => evs.BeforeHandling += (ibus, message, handler) => { if (message == null) { return; } if (exclusions != null && exclusions.Contains(message.GetType())) { return; } if (inclusions != null && !inclusions.Contains(message.GetType())) { return; } ExtendedValidator.EnsureIsValid(message); }); return(configurer); }
/// <summary> /// Initialises SQL Server storage for subscriptions and sagas, using a common convention for /// database and table names. The connection string called 'endpoint' will be used to connect /// to the database. /// </summary> /// <param name="configurer"></param> /// <param name="endpointName"></param> /// <param name="subscriptions"></param> /// <param name="sagas"></param> /// <returns></returns> public static RebusConfigurer ConfigureSqlServerStorage(this RebusConfigurer configurer, string endpointName, bool subscriptions = true, bool sagas = true) { // var environment = ConfigurationUtility.ReadAppSetting<Environment>("Environment"); // string databaseName = endpointName + "EndPoint"; // DatabaseSetupHelper.CreateDatabase(databaseName, environment); // // string subscriptionTable = string.Format("{0}.Subscription", endpointName); // string sagaTable = string.Format("{0}.Saga", endpointName); // string sagaIndexTable = string.Format("{0}.SagaIndex", endpointName); // string connectionString = ConfigurationUtility.ReadConnectionString("endpoint"); // // if (subscriptions) // { // configurer.Subscriptions(x => x.StoreInSqlServer(connectionString, subscriptionTable) // .EnsureTableIsCreated()); // } // if (sagas) // { // configurer.Sagas(x => x.StoreInSqlServer(connectionString, sagaTable, sagaIndexTable) // .EnsureTablesAreCreated()); // } return(configurer); }
/// <summary> /// Starts the bus with 0 workers, thus creating a fully functional bus, only without starting message processing. /// The returned <see cref="IBusStarter"/> can then be used to start the bus by calling <see cref="IBusStarter.Start"/> /// on it. /// </summary> public static IBusStarter Create(this RebusConfigurer configurer) { var desiredNumberOfWorkersWhenStarted = 0; var bus = configurer .Options(o => { // modify Options by setting number of workers to 0 o.Decorate(c => { var options = c.Get <Options>(); desiredNumberOfWorkersWhenStarted = options.NumberOfWorkers; // delay bus start by doing this options.NumberOfWorkers = 0; return(options); }); }) .Start(); return(new BusStarter(bus, desiredNumberOfWorkersWhenStarted)); }
/// <summary> /// Configures rebus to use sql server to store everything in one-way client mode. /// </summary> /// <param name="config">the rebus configuration</param> /// <param name="connectionStringOrName">the connectionstring or name of the connectionstring to use for sql server</param> /// <param name="queueTableName">the name of the queue table in the database</param> /// <param name="sagaDataTableName">the name of the saga data table in the database</param> /// <param name="sagaIndexTableName">the name of the saga index table in the database</param> /// <param name="subscriptionsTableName">the name of the subscriptions table in the database</param> /// <param name="timeoutTableName">the name of the timeouts table in the database</param> /// <param name="dataBusTableName">the name of the databus table in the database</param> /// <param name="enableDataBus">should rebus use a separate storage for large messages?</param> /// <param name="automaticallyCreateTables">should rebus auto-create tables?</param> /// <param name="isCenteralizedSubscriptions">is it safe to treat this as a centeralized location for subscriptions?</param> /// <returns>the rebus configuration</returns> public static RebusConfigurer UseSqlServerAsOneWayClient(this RebusConfigurer config, string connectionStringOrName, string queueTableName = "RebusMessages", string sagaDataTableName = "RebusSaga", string sagaIndexTableName = "RebusSagaIndex", string subscriptionsTableName = "RebusSubscriptions", string timeoutTableName = "RebusTimeouts", string dataBusTableName = "RebusDataBus", bool enableDataBus = true, bool automaticallyCreateTables = true, bool isCenteralizedSubscriptions = false) { return(config .Transport(t => t.UseSqlServerAsOneWayClient(connectionStringOrName, queueTableName)) .Subscriptions(s => s.StoreInSqlServer(connectionStringOrName, subscriptionsTableName, isCenteralizedSubscriptions, automaticallyCreateTables)) .Timeouts(t => t.StoreInSqlServer(connectionStringOrName, timeoutTableName, automaticallyCreateTables)) .Options(o => { if (enableDataBus) { o.EnableDataBus() .StoreInSqlServer(connectionStringOrName, dataBusTableName, automaticallyCreateTables); } })); }
internal static RebusConfigurer UseTopicNameSameAsMessageTypeNameConvetion(this RebusConfigurer rebus) => rebus .Options(o => { o.Register <ITopicNameConvention>(c => new TopicNameSameAsMessageTypeNameConvetion(c.Get <IMessageTypeNameConvention>())); });
public static RebusConfigurer UseSharedNothingApproach(this RebusConfigurer rebus, Action <CustomTypeNameConventionBuilder> builder) => rebus .UsePureJsonSerialization() .UseTopicNameSameAsMessageTypeNameConvetion() .UseTopicNameAsMessageTypePipeline() .UseCustomMessageTypeNames(builder);
protected override void ConfigurationCreated(RebusConfigurer busConfiguration) { busConfiguration.Transport(t => t.UseMongoDb(new MongoDbTransportOptions(JarvisRebusConfiguration.ConnectionString), JarvisRebusConfiguration.InputQueue)); }
protected override void ConfigurationCreated(RebusConfigurer busConfiguration) { base.ConfigurationCreated(busConfiguration); busConfiguration.Timeouts(t => t.StoreInMongoDb(_mongoDatabase, JarvisRebusConfiguration.Prefix + "-timeouts")); busConfiguration.Transport(t => t.UseMsmq(JarvisRebusConfiguration.InputQueue)); }
/// <summary> /// Installs a hook that automatically transfers the correlation ID of incoming messages to the Log4Net /// <see cref="ThreadContext"/> under the default key 'CorrelationId', allowing it to be included in the logging output. /// </summary> public static RebusConfigurer TransferCorrelationIdToLog4NetThreadContext(this RebusConfigurer configurer) { return(TransferCorrelationIdToLog4NetThreadContext(configurer, "CorrelationId")); }
public static RebusConfigurer UseTimeoutAttribute(this RebusConfigurer configurer) { return(configurer.SetTimeToBeReceivedFrom <TimeoutAttribute>(x => x.Timeout)); }
/// <summary> /// Allows user of Framework to modify rebus configuration, the perfect example is /// using specific type of logging. /// </summary> /// <param name="busConfiguration"></param> protected virtual void ConfigurationCreated(RebusConfigurer busConfiguration) { //do nothing, let the inherited member to configure whatever they want. }
public static RebusConfigurer ConfigureEndpoint(this RebusConfigurer configurer, EndpointRole role) { var dbConnectionString = Environment.GetEnvironmentVariable("REBUSSPIKE_DB"); var servicebusConnectionString = Environment.GetEnvironmentVariable("REBUSSPIKE_ASB"); configurer .Logging(l => l.Serilog(Log.Logger)) //.Transport(t => //{ // if (role == EndpointRole.Client) // { // t.UseMsmqAsOneWayClient(); // } // else // { // t.UseMsmq(Config.AppSetting("QueueName")); // } //}) .Transport(t => { if (role == EndpointRole.Client) { t.UseAzureServiceBusAsOneWayClient(servicebusConnectionString); } else { t.UseAzureServiceBus(servicebusConnectionString, "Rebus_" + Enum.GetName(typeof(EndpointRole), role)) .EnablePartitioning(); } }) //.Subscriptions(s => //{ // var subscriptionsTableName = "Rebus_Subscriptions"; // s.StoreInSqlServer(RebusDbConnectionString, subscriptionsTableName, isCentralized: true); //}) .Sagas(s => { if (role != EndpointRole.SagaHost) { return; } //var dataTableName = ; //var indexTableName = ; // store sagas in SQL Server to make them persistent and survive restarts s.StoreInSqlServer(dbConnectionString, "Rebus_SagaData", "Rebus_SagaIndex"); s.EnforceExclusiveAccess(); }) //.Timeouts(t => //{ // if (role == EndpointRole.Client) return; // var tableName = "Rebus_Timeouts"; // // store timeouts in SQL Server to make them persistent and survive restarts // t.StoreInSqlServer(RebusDbConnectionString, tableName); //}) ; return(configurer); }
/// <summary> /// Installs a hook that automatically transfers the correlation ID of incoming messages to the Log4Net /// <see cref="ThreadContext"/>, allowing it to be included in the logging output. <see cref="propertyKey"/> /// specifies the key under which the correlation ID will be set. /// </summary> public static RebusConfigurer TransferCorrelationIdToLog4NetThreadContext(this RebusConfigurer configurer, string propertyKey) { configurer.Events(e => SetLoggerPropertiesWhenAvailable(e, propertyKey)); return(configurer); }
public ServiceBusPublishEndpointConfigurationContext(RebusConfigurer configurer, string queueName, IServiceProvider serviceProvider) { Configurer = configurer; QueueName = queueName; ServiceProvider = serviceProvider; }
public static RebusConfigurer RequireTimeoutAttribute(this RebusConfigurer configurer) { return(RequireTimeToBeReceivedUsing <TimeoutAttribute>(configurer)); }
protected override void ConfigurationCreated(RebusConfigurer busConfiguration) { base.ConfigurationCreated(busConfiguration); busConfiguration.Transport(t => t.UseMsmq(JarvisRebusConfiguration.InputQueue)); }