/// <summary>
        /// Configures Rebus to use <see cref="SqlServerSubscriptionStorage"/> to store subscriptions
        /// </summary>
        public SqlServerSubscriptionStorageFluentConfigurer StoreInSqlServer(string connectionstring, string subscriptions)
        {
            var storage = new SqlServerSubscriptionStorage(connectionstring, subscriptions);

            Use(storage);
            return(new SqlServerSubscriptionStorageFluentConfigurer(storage));
        }
    /// <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,
                                        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 SqlServerSubscriptionStorage(connectionProvider, tableName, isCentralized, rebusLoggerFactory);

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

            return(subscriptionStorage);
        });
    }
        public void CanPublishWithinTransactionScopeWhenProvidingDefaultConnectionHolder()
        {
            // arrange
            var subscriptionStorage = new SqlServerSubscriptionStorage(ConnectionString, SubscriptionsTableName);

            subscriptionStorage.EnsureTableIsCreated();

            var publisher = CreateBus(PublisherInputQueueName, subscriptionStorage);

            var subReceivedEvents = new List <int>();

            var sub = CreateBus(SubscriberInputQueueName, subscriptionStorage)
                      .Handle <SomeEvent>(e => subReceivedEvents.Add(e.EventNumber));

            sub.Bus.Subscribe <SomeEvent>();

            // act
            Thread.Sleep(1.Seconds());

            using (var scope = new TransactionScope())
            {
                publisher.Bus.Publish(new SomeEvent {
                    EventNumber = 1
                });

                scope.Complete();
            }

            Thread.Sleep(1.Seconds());

            // assert
            subReceivedEvents.ShouldBe(new[] { 1 }.ToList());
        }
Beispiel #4
0
        static SqlServerSubscriptionStorage GetStorage(bool createCustomSchema)
        {
            SqlTestHelper.DropTable("Subscriptions");

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

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

                SqlTestHelper.Execute($@"

    CREATE TABLE {tableName.QualifiedName} (
	    [topic] [nvarchar](350) NOT NULL,
	    [address] [nvarchar](50) NOT NULL,
        CONSTRAINT [PK_{tableName.Schema}_{tableName.Name}] PRIMARY KEY CLUSTERED 
        (
	        [topic] ASC,
	        [address] ASC
        )
    )

");
            }
            else
            {
                storage.EnsureTableIsCreated();
            }

            storage.Initialize();

            return(storage);
        }
        public ISubscriptionStorage Create()
        {
            var storage = new SqlServerSubscriptionStorage(new DbConnectionProvider(SqlTestHelper.ConnectionString), TableName, true);

            storage.EnsureTableIsCreated();

            return(storage);
        }
        protected override void DoSetUp()
        {
            // ensure the two tables are dropped
            try { ExecuteCommand("drop table " + SubscriptionsTableName); }
            catch { }

            storage = new SqlServerSubscriptionStorage(ConnectionStrings.SqlServer, SubscriptionsTableName);
        }
        protected override void DoSetUp()
        {
            // ensure the two tables are dropped
            try { ExecuteCommand("drop table " + SubscriptionsTableName); }
            catch { }

            storage = new SqlServerSubscriptionStorage(GetOrCreateConnection, SubscriptionsTableName);
            storage.EnsureTableIsCreated();
        }
Beispiel #8
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);
        }
        protected override void SetUp()
        {
            // start clean
            SqlTestHelper.DropAllTables();

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

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

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

            _subscriberTransport = Using(new SqlServerTransport(connectionProvider, "subscriber", loggerFactory, new TplAsyncTaskFactory(loggerFactory), new FakeRebusTime(), new SqlServerTransportOptions(connectionProvider)));
            _subscriberTransport.EnsureTableIsCreated();
            _subscriberTransport.Initialize();
        }
        /// <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
#if NET45
                                            , bool enlistInAmbientTransaction = false
#endif
                                            )
        {
            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
#if NET45
                                                                  , enlistInAmbientTransaction
#endif
                                                                  );
                var subscriptionStorage = new SqlServerSubscriptionStorage(connectionProvider, tableName, isCentralized, rebusLoggerFactory);

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

                return(subscriptionStorage);
            });
        }
 internal SqlServerSubscriptionStorageFluentConfigurer(SqlServerSubscriptionStorage persister)
 {
     this.persister = persister;
 }