public AmazonSqsOptionSet() { Add <string>("region:", "The AWS region", SetRegion); Add <string>("scope:", "Account Scope", value => Scope = value); Add <string>("accesskey:", "Access Key", SetAccessKey); Add <string>("secretkey:", "Secret Key", SetSecretKey); HostAddress = new Uri("amazonsqs://localhost:4576"); Region = RegionEndpoint.APEast1; SetAccessKey("admin"); SetSecretKey("admin"); AmazonSqsConfig = new AmazonSQSConfig { ServiceURL = "http://localhost:4576" }; AmazonSnsConfig = new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localhost:4575" }; }
public void Write(string logMessage) { try { // string logMessage = this.Layout.Render(logEvent); AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig(); config.RegionEndpoint = RegionEndpoint.USEast1; AWSCredentials awsc = new BasicAWSCredentials(this.AWSKey, this.SecretKey); var sns = new AmazonSimpleNotificationServiceClient(awsc, config); sns.Publish(new PublishRequest { Message = logMessage, TopicArn = TopicARN }); } catch (AmazonSimpleNotificationServiceException ex) { //Util.LogError(ex); throw ex; } }
static async Task Main(string[] args) { var region = "eu-central-1"; AWSConfigs.AWSRegion = region; AWSConfigs.RegionEndpoint = RegionEndpoint.GetBySystemName(region); var credentials = new BasicAWSCredentials("fake", "fake"); var config = new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localhost:4575", AuthenticationRegion = region, MaxErrorRetry = 0 // to keep the client from hanging while LocalStack bugs out }; var sns = new AmazonSimpleNotificationServiceClient(credentials, config); await ListTopicsAsync(sns, null); await ListTopicsAsync(sns, string.Empty); await ListTopicsAsync(sns, ""); }
/// <summary> /// Configures Rebus to use Amazon Simple Queue Service as the message transport /// </summary> /// <param name="configurer">The configurer.</param> /// <param name="amazonCredentialsFactory">The amazon credentials factory.</param> /// <param name="amazonSqsConfig">The amazon SQS configuration.</param> /// <param name="amazonSimpleNotificationServiceConfig">The amazon simple notification service configuration.</param> /// <param name="options">The options.</param> /// <param name="topicFormatter">The topic formatter.</param> /// <param name="snsAttributeMapperBuilder">The SNS attribute mapper builder.</param> public static void UseAmazonSnsAndSqsAsOneWayClient(this StandardConfigurer <ITransport> configurer, IAmazonCredentialsFactory amazonCredentialsFactory = null, AmazonSQSConfig amazonSqsConfig = null, AmazonSimpleNotificationServiceConfig amazonSimpleNotificationServiceConfig = null, AmazonSnsAndSqsTransportOptions options = null, ITopicFormatter topicFormatter = null, SnsAttributeMapperBuilder snsAttributeMapperBuilder = null) { topicFormatter = topicFormatter ?? new ConventionBasedTopicFormatter(); amazonCredentialsFactory = amazonCredentialsFactory ?? new FailbackAmazonCredentialsFactory(); amazonSqsConfig = amazonSqsConfig ?? new AmazonSQSConfig { RegionEndpoint = RegionEndpoint.USWest2 }; options = options ?? new AmazonSnsAndSqsTransportOptions(); snsAttributeMapperBuilder = snsAttributeMapperBuilder ?? new SnsAttributeMapperBuilder(); amazonSimpleNotificationServiceConfig = amazonSimpleNotificationServiceConfig ?? new AmazonSimpleNotificationServiceConfig { RegionEndpoint = RegionEndpoint.USWest2 }; ConfigureOneWayClient(configurer, amazonCredentialsFactory, amazonSqsConfig, amazonSimpleNotificationServiceConfig, options, topicFormatter, snsAttributeMapperBuilder); }
public void Config(AmazonSimpleNotificationServiceConfig config) { _settings.AmazonSnsConfig = config; }
public async Task <bool> SendMessage(string phoneNumber, string message) { if (_isDev) { phoneNumber = _configuration["DevPhoneNumber"]; message = $"TEST ({_configuration["Region"]}) {message.Trim()}"; } if (!await ValidateNumber(phoneNumber)) { return(false); } var phone = FormatPhoneNumber(phoneNumber); if (string.IsNullOrEmpty(phone)) { return(false); } var creds = new BasicAWSCredentials(_configuration["SMSAWSCredsAccess"], _configuration["SMSAWSCredsSecret"]); AmazonSimpleNotificationServiceClient snsClient = null; //with proxy var proxyConfig = _configuration.GetValue <string>("ProxyAddress"); if (string.IsNullOrEmpty(proxyConfig)) { var config = new AmazonSimpleNotificationServiceConfig { ProxyHost = proxyConfig, RegionEndpoint = Amazon.RegionEndpoint.USEast1 }; snsClient = new AmazonSimpleNotificationServiceClient(creds, config); } else { //without proxy snsClient = new AmazonSimpleNotificationServiceClient(creds, Amazon.RegionEndpoint.USEast1); } PublishRequest request = new PublishRequest { Message = message.Trim(), PhoneNumber = phone }; request.MessageAttributes.Add("AWS.SNS.SMS.SenderID", new MessageAttributeValue { StringValue = "kbxlt2gsms", DataType = "String" }); request.MessageAttributes["AWS.SNS.SMS.MaxPrice"] = new MessageAttributeValue { StringValue = "0.50", DataType = "Number" }; request.MessageAttributes["AWS.SNS.SMS.SMSType"] = new MessageAttributeValue { StringValue = "Transactional", DataType = "String" }; PublishResponse response = await snsClient.PublishAsync(request); if (response.HttpStatusCode == HttpStatusCode.BadRequest) { throw new Exception("The phone number entered is invalid, try again. Error: AWS SNS SMS - Parameter Value Invalid"); } return(true); }
/// <summary> /// Create a client for the Amazon SimpleNotificationService Service with AWSCredentials and an AmazonSimpleNotificationService Configuration object. /// </summary> /// <param name="credentials">AWS Credentials</param> /// <param name="config">Configuration options for the service like HTTP Proxy, # of connections, etc</param> /// <returns>An Amazon SimpleNotificationService client</returns> /// <remarks> /// </remarks> public static IAmazonSimpleNotificationService CreateAmazonSimpleNotificationServiceClient(AWSCredentials credentials, AmazonSimpleNotificationServiceConfig config) { return(new AmazonSimpleNotificationServiceClient(credentials, config)); }
protected virtual void Configure(AmazonSimpleNotificationServiceConfig config) { // For derived classes to override and customise }
private static void Configure(StandardConfigurer <ITransport> configurer, IAmazonCredentialsFactory amazonCredentialsFactory, AmazonSQSConfig amazonSqsConfig, AmazonSimpleNotificationServiceConfig amazonSimpleNotificationServiceConfig, string inputQueueAddress, AmazonSnsAndSqsTransportOptions amazonSnsAndSqsTransportOptions, ITopicFormatter topicFormatter, SnsAttributeMapperBuilder snsAttributeMapperBuilder) { amazonCredentialsFactory = amazonCredentialsFactory ?? throw new ArgumentNullException(nameof(amazonCredentialsFactory)); configurer.OtherService <IAmazonCredentialsFactory>().Register(c => amazonCredentialsFactory); configurer.OtherService <IAmazonSQSTransportFactory>().Register(c => new AmazonSQSTransportFactory(c.Get <IAmazonInternalSettings>())); configurer.OtherService <IAmazonInternalSettings>().Register(c => new AmazonInternalSettings { ResolutionContext = c, AmazonSimpleNotificationServiceConfig = amazonSimpleNotificationServiceConfig ?? throw new ArgumentNullException(nameof(amazonSimpleNotificationServiceConfig)), InputQueueAddress = inputQueueAddress ?? throw new ArgumentNullException(nameof(inputQueueAddress)), AmazonSqsConfig = amazonSqsConfig ?? throw new ArgumentNullException(nameof(amazonSqsConfig)), AmazonSnsAndSqsTransportOptions = amazonSnsAndSqsTransportOptions ?? throw new ArgumentNullException(nameof(amazonSnsAndSqsTransportOptions)), MessageSerializer = new AmazonTransportMessageSerializer(), TopicFormatter = topicFormatter ?? throw new ArgumentNullException(nameof(topicFormatter)) });
public ExtendedSimpleNotificationServiceClient(AmazonSimpleNotificationServiceConfig config) : base(config) { }
/// <inheritdoc /> public virtual void Config(AmazonSimpleNotificationServiceConfig config) { _snsConfig = config; }
public Connection(string accessKey, string secretKey, RegionEndpoint regionEndpoint = null, AmazonSQSConfig amazonSqsConfig = null, AmazonSimpleNotificationServiceConfig amazonSnsConfig = null) { AccessKey = accessKey; SecretKey = secretKey; AmazonSqsConfig = amazonSqsConfig ?? new AmazonSQSConfig { RegionEndpoint = regionEndpoint ?? RegionEndpoint.USEast1 }; AmazonSnsConfig = amazonSnsConfig ?? new AmazonSimpleNotificationServiceConfig { RegionEndpoint = regionEndpoint ?? RegionEndpoint.USEast1 }; }
static async Task Main() { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .AddEnvironmentVariables() .Build(); var host = new HostBuilder() .ConfigureServices((hostBuilderContext, services) => { services.AddOptions(); services.Configure <NServiceBusOptions>(configuration.GetSection("NServiceBus")); }) .UseSerilog() .UseNServiceBus(context => { var nServiceBusOptions = configuration.GetSection("NServiceBus").Get <NServiceBusOptions>(); var endpointConfiguration = new EndpointConfiguration("Samples.FullDuplex.Server"); endpointConfiguration.DoNotCreateQueues(); var amazonSqsConfig = new AmazonSQSConfig(); if (!string.IsNullOrEmpty(nServiceBusOptions.SqsServiceUrlOverride)) { amazonSqsConfig.ServiceURL = nServiceBusOptions.SqsServiceUrlOverride; } var transport = endpointConfiguration.UseTransport <SqsTransport>(); transport.ClientFactory(() => new AmazonSQSClient( new AnonymousAWSCredentials(), amazonSqsConfig)); var amazonSimpleNotificationServiceConfig = new AmazonSimpleNotificationServiceConfig(); if (!string.IsNullOrEmpty(nServiceBusOptions.SnsServiceUrlOverride)) { amazonSimpleNotificationServiceConfig.ServiceURL = nServiceBusOptions.SnsServiceUrlOverride; } transport.ClientFactory(() => new AmazonSimpleNotificationServiceClient( new AnonymousAWSCredentials(), amazonSimpleNotificationServiceConfig)); var amazonS3Config = new AmazonS3Config { ForcePathStyle = true, }; if (!string.IsNullOrEmpty(nServiceBusOptions.S3ServiceUrlOverride)) { amazonS3Config.ServiceURL = nServiceBusOptions.S3ServiceUrlOverride; } var s3Configuration = transport.S3("bucketname", "Samples-FullDuplex-Client"); s3Configuration.ClientFactory(() => new AmazonS3Client( new AnonymousAWSCredentials(), amazonS3Config)); endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.EnableInstallers(); return(endpointConfiguration); }) .UseConsoleLifetime() .Build(); await host.RunAsync(); }
/// <inheritdoc /> public virtual IAmazonSqsHostBuilder UseConfig(AmazonSimpleNotificationServiceConfig config) { _hostConfiguratorActions.Add(configure => configure.Config(config)); return(this); }
public static AmazonSimpleNotificationService CreateAmazonSNSClient(string awsAccessKey, string awsSecretAccessKey, AmazonSimpleNotificationServiceConfig config) { return(new AmazonSimpleNotificationServiceClient(awsAccessKey, awsSecretAccessKey, config)); }
public ExtendedSimpleNotificationServiceClient(AWSCredentials credentials, AmazonSimpleNotificationServiceConfig clientConfig) : base(credentials, clientConfig) { }
/// <summary> /// Configures Rebus to use Amazon Simple Queue Service as the message transport /// </summary> public static void UseAmazonSnsAndSqs(this StandardConfigurer <ITransport> configurer, IAmazonCredentialsFactory amazonCredentialsFactory = null, AmazonSQSConfig amazonSqsConfig = null, AmazonSimpleNotificationServiceConfig amazonSimpleNotificationServiceConfig = null, string workerQueueAddress = "input_queue_address", AmazonSnsAndSqsTransportOptions amazonSnsAndSqsTransportOptions = null, ITopicFormatter topicFormatter = null, SnsAttributeMapperBuilder snsAttributeMapperBuilder = null) { configurer = configurer ?? throw new ArgumentNullException(nameof(configurer)); topicFormatter = topicFormatter ?? new ConventionBasedTopicFormatter(); amazonCredentialsFactory = amazonCredentialsFactory ?? new FailbackAmazonCredentialsFactory(); amazonSqsConfig = amazonSqsConfig ?? new AmazonSQSConfig { RegionEndpoint = RegionEndpoint.USWest2 }; amazonSnsAndSqsTransportOptions = amazonSnsAndSqsTransportOptions ?? new AmazonSnsAndSqsTransportOptions(); snsAttributeMapperBuilder = snsAttributeMapperBuilder ?? new SnsAttributeMapperBuilder(); amazonSimpleNotificationServiceConfig = amazonSimpleNotificationServiceConfig ?? new AmazonSimpleNotificationServiceConfig { RegionEndpoint = RegionEndpoint.USWest2 }; Configure(configurer, amazonCredentialsFactory, amazonSqsConfig, amazonSimpleNotificationServiceConfig, workerQueueAddress, amazonSnsAndSqsTransportOptions, topicFormatter, snsAttributeMapperBuilder); }
public ExtendedSimpleNotificationServiceClient(string awsAccessKeyId, string awsSecretAccessKey, string awsSessionToken, AmazonSimpleNotificationServiceConfig clientConfig) : base(awsAccessKeyId, awsSecretAccessKey, awsSessionToken, clientConfig) { }
protected override void ConfigureWebHost(IWebHostBuilder builder) { builder.ConfigureServices(services => { EnsureEnvVarConfigured("Localstack_SnsServiceUrl", "http://localhost:4566"); services.RemoveAll(typeof(DbContextOptions <RepairsContext>)); services.AddDbContext <RepairsContext>(options => { if (_connection != null) { options.UseNpgsql(_connection) .UseSnakeCaseNamingConvention() .UseLazyLoadingProxies(); } else { options.UseInMemoryDatabase("integration") .UseLazyLoadingProxies() .UseSnakeCaseNamingConvention(); options.ConfigureWarnings(warningOptions => { warningOptions.Ignore(InMemoryEventId.TransactionIgnoredWarning); }); } }); var serviceProvider = services.BuildServiceProvider(); InitialiseDB(serviceProvider); services.RemoveAll <IApiGateway>(); services.AddTransient <IApiGateway, MockApiGateway>(); services.RemoveAll <SOAP>(); services.RemoveAll <IAsyncNotificationClient>(); services.AddTransient(sp => _notifyMock.Object); services.AddTransient(sp => _soapMock.Object); services.RemoveAll(typeof(ILogger <>)); services.AddTransient(typeof(ILogger <>), typeof(MockLogger <>)); services.AddSingleton(_log); // Configure integration/E2E tests via localstack services.AddFilteringConfig(); services.RemoveAll <IAmazonSimpleNotificationService>(); var localstackUrl = Environment.GetEnvironmentVariable("Localstack_SnsServiceUrl"); services.AddSingleton <IAmazonSimpleNotificationService>(sp => { var clientConfig = new AmazonSimpleNotificationServiceConfig { ServiceURL = localstackUrl }; return(new AmazonSimpleNotificationServiceClient(clientConfig)); }); services.ConfigureSns(); services.AddSnsGateway(); SimpleNotificationService = serviceProvider.GetRequiredService <IAmazonSimpleNotificationService>(); AmazonSQS = new AmazonSQSClient(new AmazonSQSConfig() { ServiceURL = localstackUrl }); }) .UseEnvironment("IntegrationTests"); }
/// <summary> /// Creates a new client factory using the AwsCredentials, and the specified SQSCredentials /// </summary> /// <param name="credentials"></param> /// <param name="snsConfig"></param> public AwsClientFactory(AWSCredentials credentials, AmazonSimpleNotificationServiceConfig snsConfig) { this.credentials = credentials; this.snsConfig = snsConfig; }