コード例 #1
0
        public ISubscriptionStorage Create()
        {
            var subscriptionStorage = new MySqlSubscriptionStorage(MySqlTestHelper.ConnectionHelper, "subscriptions", true, new ConsoleLoggerFactory(false));

            subscriptionStorage.EnsureTableIsCreated();
            return(subscriptionStorage);
        }
コード例 #2
0
        /// <summary>
        /// Configures Rebus to use MySQL 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 StoreInMySql(this StandardConfigurer <ISubscriptionStorage> configurer,
                                        Func <Task <IDbConnection> > connectionFactory, string tableName, bool isCentralized = false, bool automaticallyCreateTables = true)
        {
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }
            if (connectionFactory == null)
            {
                throw new ArgumentNullException(nameof(connectionFactory));
            }
            if (tableName == null)
            {
                throw new ArgumentNullException(nameof(tableName));
            }

            configurer.Register(c =>
            {
                var rebusLoggerFactory  = c.Get <IRebusLoggerFactory>();
                var connectionProvider  = new DbConnectionFactoryProvider(connectionFactory);
                var subscriptionStorage = new MySqlSubscriptionStorage(connectionProvider, tableName, isCentralized, rebusLoggerFactory);

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

                return(subscriptionStorage);
            });
        }
コード例 #3
0
        static MySqlSubscriptionStorage GetStorage(bool createCustomSchema)
        {
            MySqlTestHelper.DropTable("Subscriptions");

            var loggerFactory      = new ConsoleLoggerFactory(false);
            var connectionProvider = new DbConnectionProvider(MySqlTestHelper.ConnectionString, loggerFactory);
            var storage            = new MySqlSubscriptionStorage(connectionProvider, "Subscriptions", true, loggerFactory);

            if (createCustomSchema)
            {
                var tableName = TableName.Parse("Subscriptions");

                MySqlTestHelper.Execute($@"
                    CREATE TABLE {tableName.QualifiedName} (
                        `topic` VARCHAR(350) NOT NULL,
	                    `address` VARCHAR(50) NOT NULL,
                        PRIMARY KEY (`topic`, `address`)
                    )");
            }
            else
            {
                storage.EnsureTableIsCreated();
            }

            return(storage);
        }
コード例 #4
0
        public ISubscriptionStorage Create()
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(true);
            var connectionProvider   = new DbConnectionProvider(MySqlTestHelper.ConnectionString, consoleLoggerFactory);
            var storage = new MySqlSubscriptionStorage(connectionProvider, TableName, true, consoleLoggerFactory);

            storage.EnsureTableIsCreated();

            return(storage);
        }
コード例 #5
0
        protected override void SetUp()
        {
            // start clean
            MySqlTestHelper.DropAllTables();

            // end clean
            Using(new DisposableCallback(MySqlTestHelper.DropAllTables));

            var loggerFactory      = new ListLoggerFactory();
            var connectionProvider = new DbConnectionProvider(MySqlTestHelper.ConnectionString, loggerFactory);

            _subscriptionStorage = new MySqlSubscriptionStorage(connectionProvider, "Subscriptions", isCentralized: true, loggerFactory);
            _subscriptionStorage.EnsureTableIsCreated();

            _subscriberTransport = Using(new MySqlTransport(connectionProvider, "subscriber", loggerFactory, new TplAsyncTaskFactory(loggerFactory), new FakeRebusTime(), new MySqlTransportOptions(connectionProvider)));
            _subscriberTransport.EnsureTableIsCreated();
            _subscriberTransport.Initialize();
        }
コード例 #6
0
        /// <summary>
        /// Configures Rebus to use MySQL 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 StoreInMySql(this StandardConfigurer <ISubscriptionStorage> configurer,
                                        string connectionString, string tableName, bool isCentralized = false,
                                        bool automaticallyCreateTables = true)
        {
            configurer.Register(c =>
            {
                var rebusLoggerFactory  = c.Get <IRebusLoggerFactory>();
                var connectionHelper    = new MySqlConnectionHelper(connectionString);
                var subscriptionStorage = new MySqlSubscriptionStorage(
                    connectionHelper, tableName, isCentralized, rebusLoggerFactory);

                if (automaticallyCreateTables)
                {
                    var createTableTask = subscriptionStorage.EnsureTableIsCreated();
                    createTableTask.Wait(); // wait at least 1min to make sure the tables are correctly created.
                    if (createTableTask.Exception != null)
                    {
                        throw createTableTask.Exception;
                    }
                }

                return(subscriptionStorage);
            });
        }