public static void ConfigureSqsTransport(this TransportExtensions <SqsTransport> transportConfiguration, string queueNamePrefix = null) { transportConfiguration.ClientFactory(() => ClientFactory.CreateSqsClient()); transportConfiguration.ClientFactory(() => ClientFactory.CreateSnsClient()); if (queueNamePrefix != null) { transportConfiguration.QueueNamePrefix(queueNamePrefix); } var s3BucketName = EnvironmentHelper.GetEnvironmentVariable(S3BucketEnvironmentVariableName); if (!string.IsNullOrEmpty(S3BucketName)) { transportConfiguration.S3(S3BucketName, "test"); } }
public override TransportInfrastructure Initialize(SettingsHolder settings, string connectionString) { var builder = new DbConnectionStringBuilder { ConnectionString = connectionString }; 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 var transport = new TransportExtensions <SqsTransport>(settings); 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."); } 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}\""); } settings.Set("NServiceBus.AmazonSQS.Region", awsRegion); if (builder.TryGetValue("QueueNamePrefix", out var queueNamePrefix)) { var queueNamePrefixAsString = (string)queueNamePrefix; if (!string.IsNullOrEmpty(queueNamePrefixAsString)) { var extensions = new TransportExtensions <SqsTransport>(settings); extensions.QueueNamePrefix(queueNamePrefixAsString); } } //HINT: This is needed to make sure Core doesn't load a connection string value from the app.config. // This prevents SQS from throwing on startup. var connectionStringSetting = settings.Get("NServiceBus.TransportConnectionString"); connectionStringSetting.GetType() .GetField("GetValue", BindingFlags.NonPublic | BindingFlags.Instance) ?.SetValue(connectionStringSetting, (Func <string>)(() => null)); // SQS doesn't support connection strings so pass in null. return(base.Initialize(settings, null)); }
public static void ConfigureSQS(this TransportExtensions <SqsTransport> extensions) { var settings = extensions.GetSettings(); bool isMessageType(Type t) => true; extensions.ClientFactory(() => new AmazonSQSClient(new EnvironmentVariablesAWSCredentials())); var ctor = typeof(MessageMetadataRegistry).GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(Func <Type, bool>) }, null); #pragma warning disable CS0618 // Type or member is obsolete settings.Set <MessageMetadataRegistry>(ctor.Invoke(new object[] { (Func <Type, bool>)isMessageType })); #pragma warning restore CS0618 // Type or member is obsolete }
public static TransportExtensions <SqsTransport> ConfigureSqsTransport(this TransportExtensions <SqsTransport> transportConfiguration, string queueNamePrefix) { transportConfiguration .ClientFactory(CreateSQSClient) .QueueNamePrefix(queueNamePrefix) .PreTruncateQueueNamesForAcceptanceTests(); var s3BucketName = EnvironmentHelper.GetEnvironmentVariable(S3BucketEnvironmentVariableName); if (!string.IsNullOrEmpty(s3BucketName)) { var s3Configuration = transportConfiguration.S3(s3BucketName, "test"); s3Configuration.ClientFactory(CreateS3Client); } return(transportConfiguration); }
public static void ConfigureSqsTransport(this TransportExtensions <SqsTransport> transportConfiguration, string queueNamePrefix = null) { transportConfiguration .ClientFactory(() => new AmazonSQSClient(new AmazonSQSConfig { RegionEndpoint = RegionEndpoint.APSoutheast2 })) .QueueNamePrefix(queueNamePrefix); var s3BucketName = EnvironmentHelper.GetEnvironmentVariable(S3BucketEnvironmentVariableName); if (!string.IsNullOrEmpty(S3BucketName)) { transportConfiguration.S3(S3BucketName, "test"); } var nativeDeferralRaw = EnvironmentHelper.GetEnvironmentVariable(NativeDeferralEnvironmentVariableName); var validValue = bool.TryParse(nativeDeferralRaw, out var nativeDeferral); if (validValue && nativeDeferral) { transportConfiguration.NativeDeferral(); } }
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); }