Esempio n. 1
0
        static TimeoutService CreateInMemoryTimeOutService()
        {
            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.
            NB: Assigning a locally installed database will cause the service to add a dependency to it. You'll have to reinstall the service if you decide later to change the service to use a remote connection string

            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();
                return new TimeoutService(storage);
            }
        }
        public void Initialize(IBusFactory busFactoryToUse)
        {
            Console.WriteLine("Purging {0}, just to be sure", TimeoutService.DefaultInputQueueName);
            MsmqUtil.PurgeQueue(TimeoutService.DefaultInputQueueName);

            //var sqlServerTimeoutStorage = new SqlServerTimeoutStorage(SqlServerFixtureBase.ConnectionString, "rebus_timeouts").EnsureTableIsCreated();
            //var mongoDbTimeoutStorage = new MongoDbTimeoutStorage(MongoDbFixtureBase.ConnectionString, "timeouts");
            var inMemoryTimeoutStorage = new InMemoryTimeoutStorage();

            timeoutService = new TimeoutService(inMemoryTimeoutStorage);
            timeoutService.Start();
            busFactory = busFactoryToUse;
        }
Esempio n. 3
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;
            }
        }