コード例 #1
0
        static async Task<List<SagaDataSnapshot>> LoadStoredCopies(DbConnectionProvider connectionProvider, string tableName)
        {
            var storedCopies = new List<SagaDataSnapshot>();

            using (var connection = await connectionProvider.GetConnection())
            {
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = string.Format(@"SELECT * FROM [{0}]", tableName);

                    using (var reader = command.ExecuteReader())
                    {
                        while (await reader.ReadAsync())
                        {
                            var sagaData = (ISagaData)new ObjectSerializer().Deserialize(Encoding.UTF8.GetBytes((string)reader["data"]));
                            var metadata = JsonConvert.DeserializeObject<Dictionary<string, string>>((string)reader["metadata"]);

                            storedCopies.Add(new SagaDataSnapshot{SagaData = sagaData, Metadata = metadata});
                        }
                    }
                }

                await connection.Complete();
            }
            return storedCopies;
        }
コード例 #2
0
        /// <summary>
        /// Constructs the storage using the specified connection provider and table to store its subscriptions. If the subscription
        /// storage is shared by all subscribers and publishers, the <paramref name="isCentralized"/> parameter can be set to true
        /// in order to subscribe/unsubscribe directly instead of sending subscription/unsubscription requests
        /// </summary>
        public SqlServerSubscriptionStorage(DbConnectionProvider connectionProvider, string tableName, bool isCentralized)
        {

            IsCentralized = isCentralized;
            _connectionProvider = connectionProvider;
            _tableName = tableName;
        }
コード例 #3
0
 public IDataBusStorage Create()
 {
     var consoleLoggerFactory = new ConsoleLoggerFactory(false);
     var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
     var sqlServerDataBusStorage = new SqlServerDataBusStorage(connectionProvider, "databus", true, consoleLoggerFactory);
     sqlServerDataBusStorage.Initialize();
     return sqlServerDataBusStorage;
 }
コード例 #4
0
 /// <summary>
 /// Configures Rebus to use SQL Server as its transport. The table specified by <paramref name="tableName"/> will be used to
 /// store messages, and the "queue" specified by <paramref name="inputQueueName"/> will be used when querying for messages.
 /// The message table will automatically be created if it does not exist.
 /// </summary>
 public static void UseSqlServer(this StandardConfigurer<ITransport> configurer, string connectionStringOrConnectionStringName, string tableName, string inputQueueName)
 {
     configurer.Register(context =>
     {
         var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName);
         var transport = new SqlServerTransport(connectionProvider, tableName, inputQueueName);
         transport.EnsureTableIsCreated();
         return transport;
     });
 }
コード例 #5
0
        public ISubscriptionStorage Create()
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(true);
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            var storage = new SqlServerSubscriptionStorage(connectionProvider, TableName, true, consoleLoggerFactory);

            storage.EnsureTableIsCreated();
            
            return storage;
        }
コード例 #6
0
        public ISagaSnapshotStorage Create()
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(true);
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);

            var snapperino = new SqlServerSagaSnapshotStorage(connectionProvider, TableName, consoleLoggerFactory);

            snapperino.EnsureTableIsCreated();

            return snapperino;
        }
コード例 #7
0
        protected override void SetUp()
        {
            var loggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, loggerFactory);

            var tableName = TestConfig.QueueName("data");

            SqlTestHelper.DropTable(tableName);

            _storage = new SqlServerDataBusStorage(connectionProvider, tableName, true, loggerFactory);
            _storage.Initialize();
        }
コード例 #8
0
        protected override void SetUp()
        {
            SqlTestHelper.DropTable(_tableName);

            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, consoleLoggerFactory);
            _transport = new SqlServerTransport(connectionProvider, _tableName, QueueName, consoleLoggerFactory);
            _transport.EnsureTableIsCreated();

            Using(_transport);

            _transport.Initialize();
        }
コード例 #9
0
        protected override void SetUp()
        {
            var loggerFactory = new ConsoleLoggerFactory(false);
            _connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, loggerFactory);

            _dataTableName = TestConfig.QueueName("sagas");
            _indexTableName = TestConfig.QueueName("sagaindex");

            SqlTestHelper.DropTable(_indexTableName);
            SqlTestHelper.DropTable(_dataTableName);

            _storage = new SqlServerSagaStorage(_connectionProvider, _dataTableName, _indexTableName, loggerFactory);
        }
コード例 #10
0
        /// <summary>
        /// Configures the data bus to store data in a central SQL Server 
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer<IDataBusStorage> configurer, string connectionStringOrConnectionStringName, string tableName, bool automaticallyCreateTables = true)
        {
            if (configurer == null) throw new ArgumentNullException(nameof(configurer));
            if (connectionStringOrConnectionStringName == null) throw new ArgumentNullException(nameof(connectionStringOrConnectionStringName));
            if (tableName == null) throw new ArgumentNullException(nameof(tableName));

            configurer.Register(c =>
            {
                var loggerFactory = c.Get<IRebusLoggerFactory>();
                var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName, loggerFactory);
                return new SqlServerDataBusStorage(connectionProvider, tableName, automaticallyCreateTables, loggerFactory);
            });
        }
コード例 #11
0
        protected override void SetUp()
        {
            var loggerFactory = new ConsoleLoggerFactory(false);
            var connectionProvider = new DbConnectionProvider(SqlTestHelper.ConnectionString, loggerFactory);

            var dataTableName = TestConfig.QueueName("sagas");
            var indexTableName = TestConfig.QueueName("sagaindex");

            SqlTestHelper.DropTable(indexTableName);
            SqlTestHelper.DropTable(dataTableName);

            _storage = new SqlServerSagaStorage(connectionProvider, dataTableName, indexTableName, loggerFactory);

            _storage.EnsureTablesAreCreated();
        }
コード例 #12
0
        /// <summary>
        /// Configures Rebus to use SQL Server to store timeouts.
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer <ITimeoutManager> configurer, string connectionStringOrConnectionStringName, string tableName, bool automaticallyCreateTables = true)
        {
            configurer.Register(c =>
            {
                var rebusLoggerFactory  = c.Get <IRebusLoggerFactory>();
                var connectionProvider  = new DbConnectionProvider(connectionStringOrConnectionStringName, rebusLoggerFactory);
                var subscriptionStorage = new SqlServerTimeoutManager(connectionProvider, tableName, rebusLoggerFactory);

                if (automaticallyCreateTables)
                {
                    subscriptionStorage.EnsureTableIsCreated();
                }

                return(subscriptionStorage);
            });
        }
コード例 #13
0
        public async Task CanDoWorkInTransaction()
        {
            var provizzle = new DbConnectionProvider(SqlTestHelper.ConnectionString);

            using (var dbConnection = await provizzle.GetConnection())
            {
                using (var cmd = dbConnection.CreateCommand())
                {
                    cmd.CommandText = "insert into bimse (text) values ('hej med dig')";
                    
                    await cmd.ExecuteNonQueryAsync();
                }

                //await dbConnection.Complete();
            }
        }
コード例 #14
0
        /// <summary>
        /// Configures Rebus to store saga snapshots in SQL Server
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer<ISagaSnapshotStorage> configurer,
            string connectionStringOrConnectionStringName, string tableName, bool automaticallyCreateTables = true)
        {
            configurer.Register(c =>
            {
                var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName);

                var snapshotStorage = new SqlServerSagaSnapshotStorage(connectionProvider, tableName);

                if (automaticallyCreateTables)
                {
                    snapshotStorage.EnsureTableIsCreated();
                }

                return snapshotStorage;
            });
        }
コード例 #15
0
        /// <summary>
        /// Configures Rebus to use SQL Server to store subscriptions. Use <paramref name="isCentralized"/> = true to indicate whether it's OK to short-circuit
        /// subscribing and unsubscribing by manipulating the subscription directly from the subscriber or just let it default to false to preserve the
        /// default behavior.
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer<ISubscriptionStorage> configurer,
            string connectionStringOrConnectionStringName, string tableName, bool isCentralized = false, bool automaticallyCreateTables = true)
        {
            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get<IRebusLoggerFactory>();
                var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName, rebusLoggerFactory);
                var subscriptionStorage = new SqlServerSubscriptionStorage(connectionProvider, tableName, isCentralized, rebusLoggerFactory);

                if (automaticallyCreateTables)
                {
                    subscriptionStorage.EnsureTableIsCreated();
                }

                return subscriptionStorage;
            });
        }
コード例 #16
0
        /// <summary>
        /// Configures Rebus to use SQL Server to store sagas, using the tables specified to store data and indexed properties respectively.
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer<ISagaStorage> configurer,
            string connectionStringOrConnectionStringName, string dataTableName, string indexTableName,
            bool automaticallyCreateTables = true)
        {
            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get<IRebusLoggerFactory>();
                var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName, rebusLoggerFactory);
                var sagaStorage = new SqlServerSagaStorage(connectionProvider, dataTableName, indexTableName, rebusLoggerFactory);

                if (automaticallyCreateTables)
                {
                    sagaStorage.EnsureTablesAreCreated();
                }

                return sagaStorage;
            });
        }
コード例 #17
0
        /// <summary>
        /// Configures Rebus to use SQL Server to store sagas, using the tables specified to store data and indexed properties respectively.
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer <ISagaStorage> configurer,
                                            string connectionStringOrConnectionStringName, string dataTableName, string indexTableName,
                                            bool automaticallyCreateTables = true)
        {
            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName, rebusLoggerFactory);
                var sagaStorage        = new SqlServerSagaStorage(connectionProvider, dataTableName, indexTableName, rebusLoggerFactory);

                if (automaticallyCreateTables)
                {
                    sagaStorage.EnsureTablesAreCreated();
                }

                return(sagaStorage);
            });
        }
コード例 #18
0
        static void Configure(StandardConfigurer<ITransport> configurer, string connectionString, string tableName, string inputQueueName)
        {
            configurer.Register(context =>
            {
                var connectionProvider = new DbConnectionProvider(connectionString);
                var transport = new SqlServerTransport(connectionProvider, tableName, inputQueueName);
                transport.EnsureTableIsCreated();
                return transport;
            });

            configurer.OtherService<ITimeoutManager>().Register(c => new DisabledTimeoutManager());

            configurer.OtherService<IPipeline>().Decorate(c =>
            {
                var pipeline = c.Get<IPipeline>();

                return new PipelineStepRemover(pipeline)
                    .RemoveIncomingStep(s => s.GetType() == typeof (HandleDeferredMessagesStep));
            });
        }
コード例 #19
0
        /// <summary>
        /// Configures Rebus to store saga snapshots in SQL Server
        /// </summary>
        public static void StoreInSqlServer(this StandardConfigurer<ISagaSnapshotStorage> configurer, 
            string connectionStringOrConnectionStringName, string tableName, bool automaticallyCreateTables = true)
        {
            if (configurer == null) throw new ArgumentNullException(nameof(configurer));
            if (connectionStringOrConnectionStringName == null) throw new ArgumentNullException(nameof(connectionStringOrConnectionStringName));
            if (tableName == null) throw new ArgumentNullException(nameof(tableName));

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get<IRebusLoggerFactory>();
                var connectionProvider = new DbConnectionProvider(connectionStringOrConnectionStringName, rebusLoggerFactory);
                var snapshotStorage = new SqlServerSagaSnapshotStorage(connectionProvider, tableName, rebusLoggerFactory);

                if (automaticallyCreateTables)
                {
                    snapshotStorage.EnsureTableIsCreated();
                }

                return snapshotStorage;
            });
        }
コード例 #20
0
ファイル: SqlServerSagaStorage.cs プロジェクト: mhertis/Rebus
 /// <summary>
 /// Constructs the saga storage, using the specified connection provider and tables for persistence.
 /// </summary>
 public SqlServerSagaStorage(DbConnectionProvider connectionProvider, string dataTableName, string indexTableName)
 {
     _connectionProvider = connectionProvider;
     _dataTableName      = dataTableName;
     _indexTableName     = indexTableName;
 }
コード例 #21
0
 /// <summary>
 /// Constructs the timeout manager, using the specified connection provider and table to store the messages until they're due.
 /// </summary>
 public SqlServerTimeoutManager(DbConnectionProvider connectionProvider, string tableName)
 {
     _connectionProvider = connectionProvider;
     _tableName = tableName;
 }
コード例 #22
0
 /// <summary>
 /// Constructs the timeout manager, using the specified connection provider and table to store the messages until they're due.
 /// </summary>
 public SqlServerTimeoutManager(DbConnectionProvider connectionProvider, string tableName)
 {
     _connectionProvider = connectionProvider;
     _tableName          = tableName;
 }
コード例 #23
0
 /// <summary>
 /// Constructs the saga storage, using the specified connection provider and tables for persistence.
 /// </summary>
 public SqlServerSagaStorage(DbConnectionProvider connectionProvider, string dataTableName, string indexTableName)
 {
     _connectionProvider = connectionProvider;
     _dataTableName = dataTableName;
     _indexTableName = indexTableName;
 }
コード例 #24
0
 /// <summary>
 /// Constructs the storage using the specified connection provider and table to store its subscriptions. If the subscription
 /// storage is shared by all subscribers and publishers, the <paramref name="isCentralized"/> parameter can be set to true
 /// in order to subscribe/unsubscribe directly instead of sending subscription/unsubscription requests
 /// </summary>
 public SqlServerSubscriptionStorage(DbConnectionProvider connectionProvider, string tableName, bool isCentralized)
 {
     IsCentralized       = isCentralized;
     _connectionProvider = connectionProvider;
     _tableName          = tableName;
 }