Example #1
0
        public static void ConfigureTransport(this TransportExtensions <AzureServiceBusTransport> transport, TransportSettings transportSettings, TransportTransactionMode transportTransactionMode)
        {
            transport.ConfigureNameShorteners();

            transport.Transactions(transportTransactionMode);
            transport.ConnectionString(transportSettings.ConnectionString);
        }
Example #2
0
        public static EndpointConfiguration CreateCommonConfiguration(string name)
        {
            string connectionString   = @"Server=192.168.0.114;Database=ServiceControlSql;User Id=sa;Password=GQI1qNeq0oEHlL;";
            EndpointConfiguration cfg = new EndpointConfiguration(name);
            PersistenceExtensions <SqlPersistence>         persistence = cfg.UsePersistence <SqlPersistence>();
            TransportExtensions <SqlServerTransport>       transport   = cfg.UseTransport <SqlServerTransport>();
            SerializationExtensions <NewtonsoftSerializer> ser         = cfg.UseSerialization <NewtonsoftSerializer>();

            cfg.AuditSagaStateChanges(serviceControlQueue: "Particular.ServiceControl.Sql");
            cfg.AuditProcessedMessagesTo("audit");
            cfg.SendFailedMessagesTo("error");
            cfg.EnableInstallers();
            cfg.DefineCriticalErrorAction(OnCriticalError);

            persistence.SqlDialect <SqlDialect.MsSqlServer>();
            persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
            persistence.SubscriptionSettings().DisableCache();

            transport.ConnectionString(connectionString);
            transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
            transport.Routing().ApplyRouting();

            RecoverabilitySettings recoverabilityConfig = cfg.Recoverability();

            recoverabilityConfig.Immediate(delegate(ImmediateRetriesSettings config)
            {
                config.NumberOfRetries(3);
            });
            recoverabilityConfig.Delayed(delegate(DelayedRetriesSettings config)
            {
                config.NumberOfRetries(3);
            });

            return(cfg);
        }
Example #3
0
        public static EndpointConfiguration GetSqlConfiguration(string name, out TransportExtensions <SqlServerTransport> transport)
        {
            const string connectionString      = "Data Source=localhost;Initial Catalog=Messages;User ID=messages_user;Password=password123";
            var          endpointConfiguration = new EndpointConfiguration(name);

            endpointConfiguration.EnableInstallers();
            endpointConfiguration.DisableFeature <TimeoutManager>();
            var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();

            persistence.SqlDialect <SqlDialect.MsSqlServer>();
            persistence.ConnectionBuilder(
                connectionBuilder: () =>
            {
                return(new SqlConnection(connectionString));
            });
            var subscriptions = persistence.SubscriptionSettings();

            subscriptions.CacheFor(TimeSpan.FromMinutes(5));

            transport = endpointConfiguration.UseTransport <SqlServerTransport>();
            transport.ConnectionString(connectionString);
            transport.Transactions(TransportTransactionMode.None);

            return(endpointConfiguration);
        }
Example #4
0
        static void ConfigureTransport(TransportExtensions <AzureStorageQueueTransport> transport, TransportSettings transportSettings)
        {
            transport.SanitizeQueueNamesWith(BackwardsCompatibleQueueNameSanitizer.Sanitize);
            transport.Transactions(TransportTransactionMode.ReceiveOnly);
            transport.ConnectionString(transportSettings.ConnectionString);

            transport.MessageInvisibleTime(TimeSpan.FromMinutes(1));
        }
Example #5
0
        public static void ConfigureTransport(this TransportExtensions <AzureServiceBusTransport> transport, TransportSettings transportSettings)
        {
            transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
            transport.ConnectionString(transportSettings.ConnectionString);

            transport.MessageReceivers().PrefetchCount(0);
            transport.Queues().LockDuration(TimeSpan.FromMinutes(5));
            transport.Subscriptions().LockDuration(TimeSpan.FromMinutes(5));
            transport.MessagingFactories().NumberOfMessagingFactoriesPerNamespace(2);
            transport.NumberOfClientsPerEntity(Math.Min(Environment.ProcessorCount, transportSettings.MaxConcurrency));
        }
Example #6
0
#pragma warning disable 618
        public static void ConfigureTransport(this TransportExtensions <AzureServiceBusTransport> transport, TransportSettings transportSettings, TransportTransactionMode transactionMode)
#pragma warning restore 618
        {
            //If the custom part stays in the connection string and is at the end, the sdk will treat is as part of the SharedAccessKey
            var connectionString = ConnectionStringPartRemover.Remove(transportSettings.ConnectionString, QueueLengthProvider.QueueLengthQueryIntervalPartName);

            transport.ConnectionString(connectionString);
            transport.Transactions(transactionMode);
            transport.Queues().LockDuration(TimeSpan.FromMinutes(5));
            transport.Subscriptions().LockDuration(TimeSpan.FromMinutes(5));
            transport.MessagingFactories().NumberOfMessagingFactoriesPerNamespace(2);
            transport.NumberOfClientsPerEntity(Math.Min(Environment.ProcessorCount, transportSettings.MaxConcurrency));
        }
Example #7
0
        public static EndpointConfiguration UseAzureServiceBusTransport(this EndpointConfiguration config,
                                                                        Func <string> connectionStringBuilder,
                                                                        Action <RoutingSettings> routing,
                                                                        Action <TransportExtensions <LearningTransport> > transportSettings)
        {
            TransportExtensions <LearningTransport> config1 = config.UseTransport <LearningTransport>();

            transportSettings?.Invoke(config1);

            config1.Transactions(TransportTransactionMode.ReceiveOnly);
            routing((RoutingSettings)config1.Routing <LearningTransport>());
            return(config);
        }
Example #8
0
        protected override async Task ExecuteAsync(CancellationToken token)
        {
            const string EndpointName          = "endpoint name";
            var          endpointConfiguration = new EndpointConfiguration(EndpointName);

            endpointConfiguration.UniquelyIdentifyRunningInstance().UsingNames(EndpointName, Environment.MachineName);


            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions
            .DefiningEventsAs(_ => _.Name.EndsWith("Event"))
            .DefiningCommandsAs(_ => _.Name.EndsWith("Command"))
            .DefiningMessagesAs(_ => _.Name.EndsWith("Message"));

            TransportExtensions <SqlServerTransport> transport =
                endpointConfiguration.UseTransport <SqlServerTransport>();

            NServiceBus.Transport.SQLServer.SubscriptionSettings
                subscriptionSettings = transport.SubscriptionSettings();
            subscriptionSettings.DisableSubscriptionCache();
            subscriptionSettings.SubscriptionTableName("subscriptions", "transportSchema");

            transport.Routing().RouteToEndpoint(
                Assembly.GetAssembly(typeof(MyCommand)),
                EndpointName);


            DelayedDeliverySettings delayedDeliverySettings = transport.NativeDelayedDelivery();

            delayedDeliverySettings.DisableTimeoutManagerCompatibility();

            transport
            .Transactions(TransportTransactionMode.ReceiveOnly)
            .ConnectionString("Data Source=sqlserver;Initial Catalog=transport;User ID=worker;Password=password;Max Pool Size=100;")
            .TransactionScopeOptions(TimeSpan.FromSeconds(30), IsolationLevel.ReadCommitted)
            .DefaultSchema("transportSchema");

            this.endpoint = await Endpoint.Start(endpointConfiguration);

            while (!token.IsCancellationRequested)
            {
                await Task.Delay(1000, token);
            }
        }
        static void ConfigureTransport(TransportExtensions <SqsTransport> transport, TransportSettings transportSettings)
        {
            var builder = new DbConnectionStringBuilder {
                ConnectionString = transportSettings.ConnectionString
            };

            PromoteEnvironmentVariableFromConnectionString(builder, "AccessKeyId", "AWS_ACCESS_KEY_ID");
            PromoteEnvironmentVariableFromConnectionString(builder, "SecretAccessKey", "AWS_SECRET_ACCESS_KEY");
            var region = PromoteEnvironmentVariableFromConnectionString(builder, "Region", "AWS_REGION");

            var awsRegion = RegionEndpoint.EnumerableAllRegions
                            .SingleOrDefault(x => x.SystemName == region);

            if (awsRegion == null)
            {
                throw new ArgumentException($"Unknown region: \"{region}\"");
            }

            if (builder.TryGetValue("QueueNamePrefix", out var queueNamePrefix))
            {
                var queueNamePrefixAsString = (string)queueNamePrefix;
                if (!string.IsNullOrEmpty(queueNamePrefixAsString))
                {
                    transport.QueueNamePrefix(queueNamePrefixAsString);
                }
            }

            //HINT: This is needed to make Core doesn't load a connection string value from the app.config.
            //      This prevents SQS from throwing on startup.
            var connectionString = transport.GetSettings().Get("NServiceBus.TransportConnectionString");

            connectionString.GetType()
            .GetField("GetValue", BindingFlags.NonPublic | BindingFlags.Instance)
            ?.SetValue(connectionString, (Func <string>)(() => null));

            transport.Transactions(TransportTransactionMode.ReceiveOnly);
        }
        static void ConfigureTransport(TransportExtensions <SqsTransport> transport, TransportSettings transportSettings)
        {
            var builder = new DbConnectionStringBuilder {
                ConnectionString = transportSettings.ConnectionString
            };

            var alwaysLoadFromEnvironmentVariable = false;

            if (builder.ContainsKey("AccessKeyId") || builder.ContainsKey("SecretAccessKey"))
            {
                PromoteEnvironmentVariableFromConnectionString(builder, "AccessKeyId", "AWS_ACCESS_KEY_ID");
                PromoteEnvironmentVariableFromConnectionString(builder, "SecretAccessKey", "AWS_SECRET_ACCESS_KEY");

                // if the user provided the access key and secret access key they should always be loaded from environment credentials
                alwaysLoadFromEnvironmentVariable = true;
                transport.ClientFactory(() => new AmazonSQSClient(new EnvironmentVariablesAWSCredentials()));
            }
            else
            {
                //See https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html#creds-assign
                log.Info("BasicAWSCredentials have not been supplied in the connection string. Attempting to use existing environment or IAM role credentials for SQS Client.");
            }

            var region = PromoteEnvironmentVariableFromConnectionString(builder, "Region", "AWS_REGION");

            var awsRegion = RegionEndpoint.EnumerableAllRegions
                            .SingleOrDefault(x => x.SystemName == region);

            if (awsRegion == null)
            {
                throw new ArgumentException($"Unknown region: \"{region}\"");
            }

            if (builder.TryGetValue("QueueNamePrefix", out var queueNamePrefix))
            {
                var queueNamePrefixAsString = (string)queueNamePrefix;
                if (!string.IsNullOrEmpty(queueNamePrefixAsString))
                {
                    transport.QueueNamePrefix(queueNamePrefixAsString);
                }
            }

            if (builder.TryGetValue("S3BucketForLargeMessages", out var bucketForLargeMessages))
            {
                var bucketForLargeMessagesAsString = (string)bucketForLargeMessages;
                if (!string.IsNullOrEmpty(bucketForLargeMessagesAsString))
                {
                    var keyPrefixAsString = string.Empty;
                    if (builder.TryGetValue("S3KeyPrefix", out var keyPrefix))
                    {
                        keyPrefixAsString = (string)keyPrefix;
                    }

                    var s3Settings = transport.S3(bucketForLargeMessagesAsString, keyPrefixAsString);
                    if (alwaysLoadFromEnvironmentVariable)
                    {
                        s3Settings.ClientFactory(() => new AmazonS3Client(new EnvironmentVariablesAWSCredentials()));
                    }
                    else
                    {
                        log.Info("BasicAWSCredentials have not been supplied in the connection string. Attempting to use existing environment or IAM role credentials for S3 Client.");
                    }
                }
            }

            //HINT: This is needed to make Core doesn't load a connection string value from the app.config.
            //      This prevents SQS from throwing on startup.
            var connectionString = transport.GetSettings().Get("NServiceBus.TransportConnectionString");

            connectionString.GetType()
            .GetField("GetValue", BindingFlags.NonPublic | BindingFlags.Instance)
            ?.SetValue(connectionString, (Func <string>)(() => null));

            transport.Transactions(TransportTransactionMode.ReceiveOnly);
        }
Example #11
0
 public static void ConfigureSql(this TransportExtensions <SqlServerTransport> extensions)
 {
     extensions.ConnectionString(EnvironmentHelper.GetEnvironmentVariable("SqlServerTransportConnectionString"));
     extensions.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
 }
 static void ConfigureTransport(TransportExtensions <RabbitMQTransport> transport, TransportSettings transportSettings)
 {
     transport.UseDirectRoutingTopology(routingKeyConvention: type => type.FullName.Replace(".", "-"));
     transport.Transactions(TransportTransactionMode.ReceiveOnly);
     transport.ConnectionString(transportSettings.ConnectionString);
 }
 public void ConfigureTransport(TransportExtensions <SqlServerTransport> transport)
 {
     transport.UseSchemaForQueue("error", "dbo");
     transport.UseSchemaForQueue("audit", "dbo");
     transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
 }
Example #14
0
 static void ConfigureTransport(TransportExtensions <RabbitMQTransport> transport, TransportSettings transportSettings)
 {
     transport.UseConventionalRoutingTopology();
     transport.Transactions(TransportTransactionMode.ReceiveOnly);
     transport.ConnectionString(transportSettings.ConnectionString);
 }