/// <summary> /// Initializes the specified aws queue URL. This needs to be called before starting the listener. /// </summary> /// <param name="awsQueueUrl">The aws queue URL.</param> /// <param name="awsRegionEndpoint">The region endpoint.</param> /// <param name="awsAccessKey">The aws access key.</param> /// <param name="awsSecretKey">The aws secret key.</param> /// <param name="isConnectedToSns">if set to <c>true</c> it assumes a SNS message structure and parsed only the "message" part of it. This is an optional feature, default is false.</param> /// <param name="longPollTimeout">The long poll timeout in seconds, AWS default is 20 seconds.</param> public void Initialize(string awsQueueUrl, string awsRegionEndpoint, string awsAccessKey, string awsSecretKey, bool isConnectedToSns = false, int longPollTimeout = 20) { VerifySingleListenerPerQueue(awsQueueUrl); var region = RegionEndpointHelper.Parse(awsRegionEndpoint); _queueUrl = awsQueueUrl; _isConnectedToSns = isConnectedToSns; _receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = awsQueueUrl, WaitTimeSeconds = longPollTimeout, MaxNumberOfMessages = 1 // make sure 1 is the default value }; AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); _sqs = new AmazonSQSClient(credentials, region); var response = _sqs.GetQueueAttributes(awsQueueUrl, new List <string> { "QueueArn" }); if (response.HttpStatusCode != HttpStatusCode.OK) { throw new AwsQueueListenerException(string.Format( "Cannot initialize AwsQueueListener. HttpStatus code {0} for queue {1} in region {2}", response.HttpStatusCode, awsQueueUrl, region)); } _logger.InfoFormat("AwsSyncQueueListener initialized for queue {0} in {1}", awsQueueUrl, region); }
/// <summary> /// Initializes the specified aws queue URL. /// </summary> /// <param name="awsTopicArn">The aws topic ARN.</param> /// <param name="regionEndpoint">The region endpoint.</param> /// <param name="awsAccessKey">The aws access key.</param> /// <param name="awsSecretKey">The aws secret key.</param> public void Initialize(string awsTopicArn, string regionEndpoint, string awsAccessKey, string awsSecretKey) { _awsTopicArn = awsTopicArn; try { AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); _client = new AmazonSimpleNotificationServiceClient(credentials, RegionEndpointHelper.Parse(regionEndpoint)); } catch (Exception e) { _logger.Error("Couldn't initialize AwsTopicPublisher!", e); } }
/// <summary> /// Initializes the specified aws queue URL. This needs to be called before starting the listener. /// </summary> /// <param name="awsQueueUrl">The aws queue URL.</param> /// <param name="awsRegionEndpoint">The region endpoint.</param> /// <param name="awsAccessKey">The aws access key.</param> /// <param name="awsSecretKey">The aws secret key.</param> /// <param name="isConnectedToSns">if set to <c>true</c> it assumes a SNS message structure and parsed only the "message" part of it. This is an optional feature, default is false.</param> /// <param name="longPollTimeout">The long poll timeout in seconds.</param> public void Initialize(string awsQueueUrl, string awsRegionEndpoint, string awsAccessKey, string awsSecretKey, bool isConnectedToSns = false, int longPollTimeout = 20) { var region = RegionEndpointHelper.Parse(awsRegionEndpoint); AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey); _sqs = new AmazonSQSClient(credentials, region); _queueUrl = awsQueueUrl; _isConnectedToSns = isConnectedToSns; _receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = awsQueueUrl, WaitTimeSeconds = longPollTimeout }; _logger.InfoFormat("AwsSyncQueueListener initialized for queue {0} in {1}", awsQueueUrl, region); }