コード例 #1
0
        static void ConfigurePubSub(TransportExtensions <SqsTransport> transport, TransportSettings transportSettings)
        {
            // precaution in case we would ever use the subscription manager
            transportSettings.Set("NServiceBus.AmazonSQS.DisableSubscribeBatchingOnStart", true);
            // will be removed in next major
#pragma warning disable 618
            transport.EnableMessageDrivenPubSubCompatibilityMode();
#pragma warning restore 618
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sergioc/ServiceControl
        static async Task Start(string[] args)
        {
            Metric.Config.WithReporting(r =>
            {
                r.WithCSVReports(".", TimeSpan.FromSeconds(5));
            });

            var customizationTypeName = SettingsReader <string> .Read(ConfigRoot, "TransportCustomization", null);

            var minLength = SettingsReader <int> .Read(ConfigRoot, "MinLength", 10000);

            var maxLength = SettingsReader <int> .Read(ConfigRoot, "MaxLength", 20000);

            var endpointName = SettingsReader <string> .Read(ConfigRoot, "EndpointName", "AuditGen");

            var connectionString = SettingsReader <string> .Read(ConfigRoot, "TransportConnectionString", "");

            HostId = Guid.NewGuid().ToString("N");

            var config = new EndpointConfiguration(endpointName);

            config.AssemblyScanner().ExcludeAssemblies("ServiceControl");
            config.UseSerialization <NewtonsoftSerializer>();

            var customization     = (TransportCustomization)Activator.CreateInstance(Type.GetType(customizationTypeName, true));
            var transportSettings = new TransportSettings
            {
                ConnectionString = connectionString
            };

            transportSettings.Set("TransportSettings.RemoteInstances", Array.Empty <string>());
            transportSettings.Set("TransportSettings.RemoteTypesToSubscribeTo", Array.Empty <Type>());

            customization.CustomizeEndpoint(config, transportSettings);

            config.UsePersistence <InMemoryPersistence>();
            config.SendFailedMessagesTo("error");
            config.EnableInstallers();
            config.RegisterComponents(c => c.RegisterSingleton(new LoadGenerators(GenerateMessages, minLength, maxLength)));

            endpointInstance = await Endpoint.Start(config);

            Console.ReadLine();
        }
コード例 #3
0
        public static Task <IStartableEndpoint> Create(Settings.Settings settings, TransportCustomization transportCustomization, TransportSettings transportSettings, LoggingSettings loggingSettings, IContainer container, Action <ICriticalErrorContext> onCriticalError, IDocumentStore documentStore, EndpointConfiguration configuration, bool isRunningAcceptanceTests)
        {
            var endpointName = settings.ServiceName;

            if (configuration == null)
            {
                configuration = new EndpointConfiguration(endpointName);
                var assemblyScanner = configuration.AssemblyScanner();
                assemblyScanner.ExcludeAssemblies("ServiceControl.Plugin");
            }

            // HACK: Yes I know, I am hacking it to pass it to RavenBootstrapper!
            configuration.GetSettings().Set <EmbeddableDocumentStore>(documentStore);
            configuration.GetSettings().Set("ServiceControl.Settings", settings);
            var remoteInstanceAddresses = settings.RemoteInstances.Select(x => x.QueueAddress).ToArray();

            configuration.GetSettings().Set("ServiceControl.RemoteInstances", remoteInstanceAddresses);
            configuration.GetSettings().Set("ServiceControl.RemoteTypesToSubscribeTo", remoteTypesToSubscribeTo);

            MapSettings(transportSettings, settings);
            transportSettings.Set("TransportSettings.RemoteInstances", remoteInstanceAddresses);
            transportSettings.Set("TransportSettings.RemoteTypesToSubscribeTo", remoteTypesToSubscribeTo);

            transportCustomization.CustomizeEndpoint(configuration, transportSettings);

            configuration.GetSettings().Set("ServiceControl.MarkerFileService", new MarkerFileService(loggingSettings.LogPath));
            configuration.GetSettings().Set <LoggingSettings>(loggingSettings);
            configuration.GetSettings().Set <IDocumentStore>(documentStore);

            // Disable Auditing for the service control endpoint
            configuration.DisableFeature <Audit>();
            configuration.DisableFeature <AutoSubscribe>();
            configuration.DisableFeature <TimeoutManager>();
            configuration.DisableFeature <Outbox>();

            configuration.EnableFeature <SubscriptionFeature>();

            var recoverability = configuration.Recoverability();

            recoverability.Immediate(c => c.NumberOfRetries(3));
            recoverability.Delayed(c => c.NumberOfRetries(0));
            configuration.SendFailedMessagesTo($"{endpointName}.Errors");

            configuration.UseSerialization <NewtonsoftSerializer>();

            configuration.LimitMessageProcessingConcurrencyTo(settings.MaximumConcurrencyLevel);

            configuration.Conventions().DefiningEventsAs(t => typeof(IEvent).IsAssignableFrom(t) || IsExternalContract(t));

            if (!isRunningAcceptanceTests)
            {
                configuration.ReportCustomChecksTo(endpointName);
            }

            configuration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));

            configuration.DefineCriticalErrorAction(criticalErrorContext =>
            {
                onCriticalError(criticalErrorContext);
                return(Task.FromResult(0));
            });

            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                configuration.EnableInstallers();
            }

            return(Endpoint.Create(configuration));
        }
コード例 #4
0
        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()));
                transport.ClientFactory(() => new AmazonSimpleNotificationServiceClient(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("TopicNamePrefix", out var topicNamePrefix))
            {
                var topicNamePrefixAsString = (string)topicNamePrefix;
                if (!string.IsNullOrEmpty(topicNamePrefixAsString))
                {
                    transport.TopicNamePrefix(topicNamePrefixAsString);
                }
            }

            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.");
                    }
                }
            }

            // precaution in case we would ever use the subscription manager
            transportSettings.Set("NServiceBus.AmazonSQS.DisableSubscribeBatchingOnStart", true);
            transport.EnableMessageDrivenPubSubCompatibilityMode();

            //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);
        }