Exemplo n.º 1
0
        static TimeoutService CreateTimeoutService()
        {
            try
            {
                var configuration = TimeoutConfigurationSection.GetSection();

                if (configuration == null)
                {
                    log.Warn("The timeout manager will use the in-memory timeout storage, which is NOT suitable for production use. For production use, you should use a SQL Server (e.g. a locally installed SQL Express).");

                    var storage        = new InMemoryTimeoutStorage();
                    var timeoutService = new TimeoutService(storage);

                    return(timeoutService);
                }

                EnsureIsSet(configuration.InputQueue);
                EnsureIsSet(configuration.StorageType);

                switch (configuration.StorageType.ToLowerInvariant())
                {
                case "sql":
                    log.Info("Using the SQL timeout storage - the default table name '{0}' will be used", DefaultTimeoutsTableName);
                    return(new TimeoutService(new SqlServerTimeoutStorage(configuration.Parameters, DefaultTimeoutsTableName), configuration.InputQueue));

                default:
                    throw new ArgumentException(
                              string.Format("Cannot use the value '{0}' as the storage type... sorry!",
                                            configuration.StorageType));
                }
            }
            catch (Exception e)
            {
                log.Error(e, "An error occurred while attempting to configure the timeout manager");
                throw;
            }
        }
Exemplo n.º 2
0
        static TimeoutService CreateTimeoutService()
        {
            try
            {
                var configuration = TimeoutConfigurationSection.GetSection();

                if (configuration == null)
                {
                    log.Warn(@"The timeout manager will use the MSMQ queue '{0}' as its input queue because the input queue name has not been explicitly configured.

The timeout manager will use the in-memory timeout storage, which is NOT suitable for production use. For production use, you should use a SQL Server (e.g. a locally installed SQL Express) or another durable database.

If you want to configure the timeout manager for production use, you can use one the following examples to get started:

    <timeout inputQueue=""rebus.timeout.input"" errorQueue=""rebus.timeout.error"" storageType=""SQL"" 
             connectionString=""server=.;initial catalog=RebusTimeoutManager;integrated security=sspi""
             tableName=""timeouts"" />

to use the 'timeouts' table in the RebusTimeoutManager database to store timeouts. If the specified table does not exist, the timeout manager will try to create it automatically.

You can also configure the timeout manager to store timeouts in MongoDB like this:

    <timeout inputQueue=""rebus.timeout.input"" errorQueue=""rebus.timeout.error"" storageType=""mongodb"" 
             connectionString=""mongodb://localhost/SomeDatabase""
             tableName=""timeouts"" />

to use the 'timeouts' collection in the SomeDatabase database to store timeouts. Please don't use the collection to store anything besides Rebus' timeouts, because otherwise it might lead to unexpected behavior.",
                             TimeoutService.DefaultInputQueueName);

                    var storage        = new InMemoryTimeoutStorage();
                    var timeoutService = new TimeoutService(storage);

                    return(timeoutService);
                }

                EnsureIsSet(configuration.InputQueue);
                EnsureIsSet(configuration.ErrorQueue);
                EnsureIsSet(configuration.StorageType);
                EnsureIsSet(configuration.TableName);

                switch (configuration.StorageType.ToLowerInvariant())
                {
                case "sql":
                    log.Info("Using the SQL timeout storage - the table name '{0}' will be used", configuration.TableName);
                    return
                        (new TimeoutService(
                             new SqlServerTimeoutStorage(configuration.ConnectionString, configuration.TableName)
                             .EnsureTableIsCreated(), configuration.InputQueue, configuration.ErrorQueue));

                case "mongodb":
                    log.Info("Using the MongoDB timeout storage - the collection name '{0}' will be used",
                             configuration.TableName);
                    return(new TimeoutService(
                               new MongoDbTimeoutStorage(configuration.ConnectionString, configuration.TableName),
                               configuration.InputQueue, configuration.ErrorQueue));

                default:
                    throw new ArgumentException(
                              string.Format("Cannot use the value '{0}' as the storage type... sorry!",
                                            configuration.StorageType));
                }
            }
            catch (Exception e)
            {
                log.Error(e, "An error occurred while attempting to configure the timeout manager");
                throw;
            }
        }