Пример #1
0
        public RealSimulator(string address, string connectionString)
        {
            this.address = address;
            var localConnectionParams = new LocalConnectionParams(null, connectionString, "dbo");

            new SqlServerQueueCreator(new DefaultConnectionStringProvider(localConnectionParams), ConnectionFactory.Default()).CreateQueueIfNecessary(Address.Parse(address), null);

            var transportNotifications = new TransportNotifications();

            taskStarted = transportNotifications.ReceiveTaskStarted.Subscribe(x => AddMessage("Thread started"));
            taskEnded   = transportNotifications.ReceiveTaskStopped.Subscribe(x => AddMessage("Thread died"));

            var purgeExpiredMessagesParams = new PurgeExpiredMessagesParams
            {
                PurgeTaskDelay = Timeout.InfiniteTimeSpan,
                PurgeBatchSize = 1
            };

            dequeueStrategy = new SqlServerPollingDequeueStrategy(localConnectionParams,
                                                                  new ReceiveStrategyFactory(new DummyConnectionStore(), localConnectionParams, Address.Parse("error"), ConnectionFactory.Default()),
                                                                  new QueuePurger(new SecondaryReceiveConfiguration(_ => SecondaryReceiveSettings.Disabled()), localConnectionParams, ConnectionFactory.Default()),
                                                                  new SecondaryReceiveConfiguration(_ => SecondaryReceiveSettings.Disabled()),
                                                                  transportNotifications,
                                                                  new RepeatedFailuresOverTimeCircuitBreaker("A", TimeSpan.FromDays(1000), _ => { }),
                                                                  ConnectionFactory.Default(),
                                                                  purgeExpiredMessagesParams);

            dequeueStrategy.Init(Address.Parse(address), new TransactionSettings(true, TimeSpan.FromMinutes(2), System.Transactions.IsolationLevel.ReadCommitted, 1, false, false),
                                 ProcessMessage, (message, exception) => { });

            sender = new SqlServerMessageSender(new DefaultConnectionStringProvider(localConnectionParams), new DummyConnectionStore(), new DummyCallbackAddressStore(), ConnectionFactory.Default());
        }
Пример #2
0
        IConnectionStringProvider CreateConfigPerEndpointConnectionStringProvider(LocalConnectionParams localConnectionParams)
        {
            const string transportConnectionStringPrefix = "NServiceBus/Transport/";
            var          configConnectionStrings         =
                connectionStrings
                .Where(x => x.Name.StartsWith(transportConnectionStringPrefix))
                .Select(x =>
            {
                string schema;
                var connectionString = x.ConnectionString.ExtractSchemaName(out schema);
                var endpoint         = x.Name.Replace(transportConnectionStringPrefix, String.Empty);
                var connectionInfo   = EndpointConnectionInfo.For(endpoint).UseSchema(schema);

                var localConnectionStringBuilder = new DbConnectionStringBuilder {
                    ConnectionString = localConnectionParams.ConnectionString
                };
                var overriddenConnectionStringBuilder = new DbConnectionStringBuilder {
                    ConnectionString = connectionString
                };

                if (!localConnectionStringBuilder.EquivalentTo(overriddenConnectionStringBuilder))
                {
                    connectionInfo = connectionInfo.UseConnectionString(connectionString);
                }
                return(connectionInfo);
            })
                .ToArray();

            return(new CollectionConnectionStringProvider(configConnectionStrings, localConnectionParams));
        }
        IConnectionStringProvider CreateConfigPerEndpointConnectionStringProvider(LocalConnectionParams localConnectionParams)
        {
            const string transportConnectionStringPrefix = "NServiceBus/Transport/";
            var configConnectionStrings =
                connectionStrings
                    .Where(x => x.Name.StartsWith(transportConnectionStringPrefix))
                    .Select(x =>
                    {
                        string schema;
                        var connectionString = x.ConnectionString.ExtractSchemaName(out schema);
                        var endpoint = x.Name.Replace(transportConnectionStringPrefix, String.Empty);
                        var connectionInfo = EndpointConnectionInfo.For(endpoint).UseSchema(schema);

                        var localConnectionStringBuilder = new DbConnectionStringBuilder { ConnectionString = localConnectionParams.ConnectionString };
                        var overriddenConnectionStringBuilder = new DbConnectionStringBuilder { ConnectionString = connectionString };

                        if (!localConnectionStringBuilder.EquivalentTo(overriddenConnectionStringBuilder))
                        {
                            connectionInfo = connectionInfo.UseConnectionString(connectionString);
                        }
                        return connectionInfo;
                    })
                    .ToArray();

            return new CollectionConnectionStringProvider(configConnectionStrings, localConnectionParams);
        }
        public override void Configure(FeatureConfigurationContext context, string connectionStringWithSchema)
        {
            var defaultSchema = context.Settings.GetOrDefault<string>(DefaultSchemaSettingsKey);
            string configStringSchema;
            var connectionString = connectionStringWithSchema.ExtractSchemaName(out configStringSchema);
            var localConnectionParams = new LocalConnectionParams(configStringSchema, connectionString, defaultSchema);
            context.Container.ConfigureComponent(() => localConnectionParams, DependencyLifecycle.SingleInstance);

            var connectionStringProvider = ConfigureConnectionStringProvider(context, localConnectionParams);
            context.Container.ConfigureComponent<IConnectionStringProvider>(() => connectionStringProvider, DependencyLifecycle.SingleInstance);
        }
Пример #5
0
        public override void Configure(FeatureConfigurationContext context, string connectionStringWithSchema)
        {
            var    defaultSchema = context.Settings.GetOrDefault <string>(DefaultSchemaSettingsKey);
            string configStringSchema;
            var    connectionString      = connectionStringWithSchema.ExtractSchemaName(out configStringSchema);
            var    localConnectionParams = new LocalConnectionParams(configStringSchema, connectionString, defaultSchema);

            context.Container.ConfigureComponent(() => localConnectionParams, DependencyLifecycle.SingleInstance);

            var connectionStringProvider = ConfigureConnectionStringProvider(context, localConnectionParams);

            context.Container.ConfigureComponent <IConnectionStringProvider>(() => connectionStringProvider, DependencyLifecycle.SingleInstance);
        }
        CompositeConnectionStringProvider ConfigureConnectionStringProvider(FeatureConfigurationContext context, LocalConnectionParams localConnectionParams)
        {
            var configProvidedPerEndpointConnectionStrings = CreateConfigPerEndpointConnectionStringProvider(localConnectionParams);
            var programmaticallyProvidedPerEndpointConnectionStrings = CreateProgrammaticPerEndpointConnectionStringProvider(context, localConnectionParams);

            var connectionStringProvider = new CompositeConnectionStringProvider(
                configProvidedPerEndpointConnectionStrings,
                programmaticallyProvidedPerEndpointConnectionStrings,
                new DefaultConnectionStringProvider(localConnectionParams)
                );

            return connectionStringProvider;
        }
 static IConnectionStringProvider CreateProgrammaticPerEndpointConnectionStringProvider(FeatureConfigurationContext context, LocalConnectionParams localConnectionParams)
 {
     var collection = context.Settings.GetOrDefault<IEnumerable<EndpointConnectionInfo>>(PerEndpointConnectionStringsCollectionSettingKey);
     if (collection != null)
     {
         return new CollectionConnectionStringProvider(collection, localConnectionParams);
     }
     var callback = context.Settings.GetOrDefault<Func<string, ConnectionInfo>>(PerEndpointConnectionStringsCallbackSettingKey);
     if (callback != null)
     {
         return new DelegateConnectionStringProvider(callback, localConnectionParams);
     }
     return new NullConnectionStringProvider();
 }
        CompositeConnectionStringProvider ConfigureConnectionStringProvider(FeatureConfigurationContext context, LocalConnectionParams localConnectionParams)
        {
            const string transportConnectionStringPrefix = "NServiceBus/Transport/";
            var configConnectionStrings =
                connectionStrings
                    .Where(x => x.Name.StartsWith(transportConnectionStringPrefix))
                    .Select(x =>
                    {
                        string schema;
                        var connectionString = x.ConnectionString.ExtractSchemaName(out schema);
                        var endpoint = x.Name.Replace(transportConnectionStringPrefix, String.Empty);
                        return EndpointConnectionInfo.For(endpoint).UseConnectionString(connectionString).UseSchema(schema);
                    });

            var configProvidedPerEndpointConnectionStrings = new CollectionConnectionStringProvider(configConnectionStrings, localConnectionParams);
            var programmaticallyProvidedPerEndpointConnectionStrings = CreateProgrammaticPerEndpointConnectionStringProvider(context, localConnectionParams);

            var connectionStringProvider = new CompositeConnectionStringProvider(
                configProvidedPerEndpointConnectionStrings,
                programmaticallyProvidedPerEndpointConnectionStrings,
                new DefaultConnectionStringProvider(localConnectionParams)
                );
            return connectionStringProvider;
        }
 public DefaultConnectionStringProvider(LocalConnectionParams localConnectionParams)
 {
     this.localConnectionParams = localConnectionParams;
 }
Пример #10
0
 internal ConnectionParams CreateConnectionParams(LocalConnectionParams localConnectionParams)
 {
     return(localConnectionParams.MakeSpecific(connectionString, schemaName));
 }
 internal ConnectionParams CreateConnectionParams(LocalConnectionParams localConnectionParams)
 {
     return localConnectionParams.MakeSpecific(connectionString, schemaName);
 }
Пример #12
0
        static IConnectionStringProvider CreateProgrammaticPerEndpointConnectionStringProvider(FeatureConfigurationContext context, LocalConnectionParams localConnectionParams)
        {
            var collection = context.Settings.GetOrDefault <IEnumerable <EndpointConnectionInfo> >(PerEndpointConnectionStringsCollectionSettingKey);

            if (collection != null)
            {
                return(new CollectionConnectionStringProvider(collection, localConnectionParams));
            }
            var callback = context.Settings.GetOrDefault <Func <string, ConnectionInfo> >(PerEndpointConnectionStringsCallbackSettingKey);

            if (callback != null)
            {
                return(new DelegateConnectionStringProvider(callback, localConnectionParams));
            }
            return(new NullConnectionStringProvider());
        }
Пример #13
0
        CompositeConnectionStringProvider ConfigureConnectionStringProvider(FeatureConfigurationContext context, LocalConnectionParams localConnectionParams)
        {
            const string transportConnectionStringPrefix = "NServiceBus/Transport/";
            var          configConnectionStrings         =
                connectionStrings
                .Where(x => x.Name.StartsWith(transportConnectionStringPrefix))
                .Select(x =>
            {
                string schema;
                var connectionString = x.ConnectionString.ExtractSchemaName(out schema);
                var endpoint         = x.Name.Replace(transportConnectionStringPrefix, String.Empty);
                return(EndpointConnectionInfo.For(endpoint).UseConnectionString(connectionString).UseSchema(schema));
            });

            var configProvidedPerEndpointConnectionStrings           = new CollectionConnectionStringProvider(configConnectionStrings, localConnectionParams);
            var programmaticallyProvidedPerEndpointConnectionStrings = CreateProgrammaticPerEndpointConnectionStringProvider(context, localConnectionParams);

            var connectionStringProvider = new CompositeConnectionStringProvider(
                configProvidedPerEndpointConnectionStrings,
                programmaticallyProvidedPerEndpointConnectionStrings,
                new DefaultConnectionStringProvider(localConnectionParams)
                );

            return(connectionStringProvider);
        }
Пример #14
0
        CompositeConnectionStringProvider ConfigureConnectionStringProvider(FeatureConfigurationContext context, LocalConnectionParams localConnectionParams)
        {
            var configProvidedPerEndpointConnectionStrings           = CreateConfigPerEndpointConnectionStringProvider(localConnectionParams);
            var programmaticallyProvidedPerEndpointConnectionStrings = CreateProgrammaticPerEndpointConnectionStringProvider(context, localConnectionParams);

            var connectionStringProvider = new CompositeConnectionStringProvider(
                configProvidedPerEndpointConnectionStrings,
                programmaticallyProvidedPerEndpointConnectionStrings,
                new DefaultConnectionStringProvider(localConnectionParams)
                );

            return(connectionStringProvider);
        }
 public DefaultConnectionStringProvider(LocalConnectionParams localConnectionParams)
 {
     this.localConnectionParams = localConnectionParams;
 }