private static void AddQueueService(IServiceCollection services) { if (Config.IsLocal) { services.AddSingleton <IQueueService, LocalQueueService>(); } else { var amazonSqs = new AmazonSQSClient(RegionEndpoint.GetBySystemName(Config.AwsRegionEndpoint)); services.AddSingleton <IAmazonSQS>(q => amazonSqs); services.AddSingleton <IQueueService, AwsQueueService>(); } }
public static IEnumerable <string> Poll(string accessKey, string secretKey, string attribute, int maxMessages, string url, int timeout, int wait) { var awsCreds = new BasicAWSCredentials(accessKey, secretKey); var sqs = new AmazonSQSClient(awsCreds, RegionEndpoint.EUWest1); var request = CreateSQSRequest(attribute, maxMessages, url, timeout, wait); var receivedMessages = sqs.ReceiveMessageAsync(request).Result; var messageStrings = receivedMessages.Messages.Select(x => x.Body); return(messageStrings); }
private static int NumbersOfMessagesInQueue(string queueUrl, AmazonSQSClient sqsClient) { GetQueueAttributesRequest attReq = new GetQueueAttributesRequest(); attReq.QueueUrl = queueUrl; attReq.AttributeNames.Add("ApproximateNumberOfMessages"); GetQueueAttributesResponse response = Task.Run(async() => await sqsClient.GetQueueAttributesAsync(attReq)).Result; var retval = response.ApproximateNumberOfMessages; return(retval); }
public static async Task <string> CreateQueue(string name) { using (var client = new AmazonSQSClient(ConfigManager.ConfigSettings.AccessKey, ConfigManager.ConfigSettings.Secret, Amazon.RegionEndpoint.USWest2)) { var request = new CreateQueueRequest { QueueName = name }; var response = await client.CreateQueueAsync(request); return(response.QueueUrl); } }
private async Task CheckQueueForNewStatus(CancellationToken cancellationToken) { try { var sqs = new AmazonSQSClient(RegionEndpoint.EUWest1); var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = "https://sqs.eu-west-1.amazonaws.com/166778461577/StatusCheckSchedulerNotifierQueue" }; ReceiveMessageResponse receiveMessageResponse = null; try { receiveMessageResponse = await sqs.ReceiveMessageAsync(receiveMessageRequest, cancellationToken); } catch (Exception ex) { _logger.LogError(ex, "Error in scheduler while working with SQS"); } if (receiveMessageResponse?.Messages != null && receiveMessageResponse.Messages.Any()) { int counter = -1; foreach (var message in receiveMessageResponse.Messages) { counter++; if (!string.IsNullOrEmpty(message.Body)) { var dto = JsonHelper.ReadObject <AwsSnsMessageDto>(message.Body); var status = JsonHelper.ReadObject <VehicleStatusModel>(dto.Message); OnNewStatusArrived(new NewVehicleStatusEventArgs(status)); } var messageRecieptHandle = receiveMessageResponse.Messages[counter].ReceiptHandle; var deleteRequest = new DeleteMessageRequest { QueueUrl = "https://sqs.eu-west-1.amazonaws.com/166778461577/StatusCheckSchedulerNotifierQueue", ReceiptHandle = messageRecieptHandle }; await sqs.DeleteMessageAsync(deleteRequest, cancellationToken); } } } catch (AmazonSQSException ex) { _logger.LogError(ex, "Error in scheduler while working with SQS"); // do nothing, you may want to log, but let it give it another try in the next run } }
public static async Task DeleteAllQueues() { using (var client = new AmazonSQSClient(ConfigManager.ConfigSettings.AccessKey, ConfigManager.ConfigSettings.Secret, Amazon.RegionEndpoint.USWest2)) { var response = await client.ListQueuesAsync(new ListQueuesRequest()); foreach (var queueUrl in response.QueueUrls) { await PurgeQueueByQueueUrl(queueUrl); await client.DeleteQueueAsync(queueUrl); } } }
public MessageQueue(IMapper mapper) { if (_sqsClient == null) { var sqsConfig = new AmazonSQSConfig { ServiceURL = ConfigurationManager.AppSettings["ServiceUrl"] }; _sqsClient = new AmazonSQSClient(sqsConfig); } _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); }
public static AmazonSQSClient GetSQSClient() { if (client == null) { AWSCredentials awsCredentials = null; if (GetCredentials(out awsCredentials)) { client = new AmazonSQSClient(awsCredentials, RegionEndpoint.USWest2); } } return(client); }
//This will house the vendor orders for loan setup phase 1 milestone public override void MilestoneCompleted(object sender, MilestoneEventArgs milestoneEventArgs) { Loan loan = EncompassApplication.CurrentLoan; var milestone = milestoneEventArgs.MilestoneEvent.MilestoneName; string titleCompany = loan.Fields["411"].ToString(); string titleComment = loan.Fields["419"].ToString(); SilkTitleOrderResponse orderTitleResponse = new SilkTitleOrderResponse(); string msgforUser = null; switch (milestone.ToLower()) { case "loan setup phase 1": if (loan.Fields["187"].IsEmpty()) { if ((titleCompany.Contains("Silk") || titleComment.Contains("Silk")) && loan.Fields["19"].ToString().Contains("Refi")) { Task titleTask = new TaskFactory().StartNew(() => { orderTitleResponse = OrderSilkTitle(loan); }).ContinueWith((x) => { if (orderTitleResponse.WasSuccessful) { bool sendOrderDocsToSilk = PostPreliminaryTitleOrderDocsToSilk(loan, orderTitleResponse.Id, out msgforUser); } }); } } //SF send loan to queue to order flood/ fraud - LoanEventModel request = new LoanEventModel { LoanNumber = loan.LoanNumber, UserId = loan.Session.UserID, EventType = "Order", LoanGuid = loan.Guid }; using (IAmazonSQS sqs = new AmazonSQSClient(AwsSettings.AwsAccessKey, AwsSettings.AwsSecretKey, RegionEndpoint.USEast1)) { SendMessageRequest queueRequest = new SendMessageRequest { MessageBody = JsonConvert.SerializeObject(request), QueueUrl = AwsSettings.VendorQueueUrl, }; sqs.SendMessageAsync(queueRequest); } break; } }
private void Initialize() { try { string ak = _configuration.GetSection("AWS:AcessKey").Value; string sk = _configuration.GetSection("AWS:SecretKey").Value; aWSCredentials = new BasicAWSCredentials(ak, sk); amazonSQSClient = new AmazonSQSClient(aWSCredentials, Amazon.RegionEndpoint.SAEast1); } catch (Exception e) { throw e; } }
public async Task <IActionResult> Index(IFormFile profileImage) { var randomName = Path.GetRandomFileName().Replace(".", ""); var fileName = System.IO.Path.GetFileName(profileImage.FileName); var newFileName = $"{ randomName }{ Path.GetExtension(profileImage.FileName)}"; var path = $"upload/{randomName}{Path.GetExtension(profileImage.FileName)}"; if (!System.IO.File.Exists(path)) { using (var imageFile = System.IO.File.OpenWrite(path)) { using (var uploadedfile = profileImage.OpenReadStream()) { uploadedfile.CopyTo(imageFile); } } } var client = new AmazonS3Client(); var file = new FileInfo(path); var request = new PutObjectRequest { BucketName = "practicenet", FilePath = file.FullName, Key = newFileName }; var response = await client.PutObjectAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { var sqsClient = new AmazonSQSClient(); var sqsRequest = new SendMessageRequest { QueueUrl = "https://sqs.us-east-1.amazonaws.com/675681942151/success", MessageBody = $"name: '{newFileName}'" }; var sqsResponse = await sqsClient.SendMessageAsync(sqsRequest); if (sqsResponse.HttpStatusCode == System.Net.HttpStatusCode.OK) { file.Delete(); } } return(View()); }
private void CreateTopic(RoutingKey topicName, AmazonSQSClient sqsClient, AmazonSimpleNotificationServiceClient snsClient) { //topic re-creation is a no-op, so don't bother to check first as reduces latency var createTopic = snsClient.CreateTopicAsync(new CreateTopicRequest(topicName)).Result; if (!string.IsNullOrEmpty(createTopic.TopicArn)) { _channelTopicARN = createTopic.TopicArn; } else { throw new InvalidOperationException($"Could not create Topic topic: {topicName} on {_awsConnection.Region}"); } }
private void SendMessageToSilkQueue(SilkEvent request) { using (IAmazonSQS sqs = new AmazonSQSClient(AwsSettings.AwsAccessKey, AwsSettings.AwsSecretKey, RegionEndpoint.USEast1)) { SendMessageRequest queueRequest = new SendMessageRequest { MessageBody = JsonConvert.SerializeObject(request), QueueUrl = AwsSettings.SilkProcessingQueueUrl }; sqs.SendMessageAsync(queueRequest); } }
private async Task RemoveProcessedMessagesFromQueue(List <DeleteMessageBatchRequestEntry> processedMessages) { if (processedMessages.Count > 0) { var client = new AmazonSQSClient(); var delRequest = new DeleteMessageBatchRequest { Entries = processedMessages, QueueUrl = Environment.GetEnvironmentVariable("LoansEventsQueue") }; await client.DeleteMessageBatchAsync(delRequest); } }
public Function() { this.config = new AmazonS3StorageConfig { AccessKey = "AKIAJTXMJ7UJ47CT27GA", //Environment.GetEnvironmentVariable("accessKey"), SecretKey = "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" //Environment.GetEnvironmentVariable("secretKey"), }; this.credentials = new BasicAWSCredentials(this.config.AccessKey, this.config.SecretKey); this.rekClient = new AmazonRekognitionClient(this.credentials, RegionEndpoint.USEast1); this.sqsClient = new AmazonSQSClient(this.credentials, RegionEndpoint.USEast1); }
IAsyncTask CreateRenewalTaskForMessage(Message message, AmazonSQSClient client) { return(_asyncTaskFactory.Create($"RenewPeekLock-{message.MessageId}", async() => { _log.Info("Renewing peek lock for message with ID {0}", message.MessageId); await client.ChangeMessageVisibilityAsync(new ChangeMessageVisibilityRequest(_queueUrl, message.ReceiptHandle, (int)_peekLockDuration.TotalSeconds)); }, intervalSeconds: (int)_peekLockRenewalInterval.TotalSeconds, prettyInsignificant: true)); }
private async Task <Boolean> SendMessageAsync(String emailBody, String emailTo, String emailFrom) { try { AmazonSQSClient amazonSQSClient = new AmazonSQSClient(sqsRegion); try { SendMessageRequest sendMessageRequest = new SendMessageRequest(); sendMessageRequest.QueueUrl = secrets.sqsEmailURL; sendMessageRequest.MessageBody = emailBody; Dictionary <string, MessageAttributeValue> MessageAttributes = new Dictionary <string, MessageAttributeValue>(); MessageAttributeValue messageTypeAttribute1 = new MessageAttributeValue(); messageTypeAttribute1.DataType = "String"; messageTypeAttribute1.StringValue = "???"; MessageAttributes.Add("Name", messageTypeAttribute1); MessageAttributeValue messageTypeAttribute2 = new MessageAttributeValue(); messageTypeAttribute2.DataType = "String"; messageTypeAttribute2.StringValue = emailTo; MessageAttributes.Add("To", messageTypeAttribute2); MessageAttributeValue messageTypeAttribute3 = new MessageAttributeValue(); messageTypeAttribute3.DataType = "String"; messageTypeAttribute3.StringValue = "West Northants Council: Your Call Number is " + caseReference;; MessageAttributes.Add("Subject", messageTypeAttribute3); MessageAttributeValue messageTypeAttribute4 = new MessageAttributeValue(); messageTypeAttribute4.DataType = "String"; messageTypeAttribute4.StringValue = emailFrom; MessageAttributes.Add("From", messageTypeAttribute4); sendMessageRequest.MessageAttributes = MessageAttributes; SendMessageResponse sendMessageResponse = await amazonSQSClient.SendMessageAsync(sendMessageRequest); } catch (Exception error) { await SendFailureAsync("Error sending SQS message", error.Message); Console.WriteLine("ERROR : SendMessageAsync : Error sending SQS message : '{0}'", error.Message); Console.WriteLine("ERROR : SendMessageAsync : " + error.StackTrace); return(false); } } catch (Exception error) { await SendFailureAsync("Error starting AmazonSQSClient", error.Message); Console.WriteLine("ERROR : SendMessageAsync : Error starting AmazonSQSClient : '{0}'", error.Message); Console.WriteLine("ERROR : SendMessageAsync : " + error.StackTrace); return(false); } return(true); }
static void Main(string[] args) { Console.WriteLine("Pushing Messages to Aws Queue..........."); Study s1; IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.APSouth1); var queueUrl = "https://sqs.ap-south-1.amazonaws.com/066325793814/cytel-load-test.fifo"; //var sqsRequest = new CreateQueueRequest() //{ // QueueName = "CytelSimulationQueueTest", //}; //var createQueueResponse = sqs.CreateQueueAsync(sqsRequest).Result; //var myQueueQurl = createQueueResponse.QueueUrl; //var listQueuesRequest = new ListQueuesRequest(); //var listQueuesResponse = sqs.ListQueuesAsync(listQueuesRequest); //Console.WriteLine("List of Queues"); //foreach(var queueUrl in listQueuesResponse.Result.QueueUrls) //{ // Console.WriteLine($"Queue Url: {queueUrl}"); //} for (int i = 1; i <= 5000; i++) { s1 = new Study { StudyName = $"Study- {i}", StudyStartDate = "01 Jan 2010", EstimatedCompletionDate = "05 Jan 2019", ProtocolID = $"ProtocolID - {i}", StudyGroup = $"Groupd - {i}", Phase = "Phase1", PrimaryIndication = "Indication 1", SecondaryIndication = "Secondary Indication1" }; var sqsmessageRequest = new SendMessageRequest() { QueueUrl = queueUrl, MessageBody = JsonConvert.SerializeObject(s1), MessageGroupId = "CytelMessages1", MessageDeduplicationId = $"CytemDeduplication{i}" }; sqs.SendMessageAsync(sqsmessageRequest); } Console.WriteLine("Completed Sending messages....."); Console.ReadLine(); }
/** * Process a message * See https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/servicebus/service-bus#register-message-handler */ private static void messageHandler(Message message, AmazonSQSClient queue) { string test = null; string xml = null; // If there is an error the program will catch it and the JSONCreated will change to false bool JSONCreated = true; string ReceiptHandle = message.ReceiptHandle; if (DSConfig.Debug.Equals("true")) { String str = " Processing message id " + message.MessageId; Console.WriteLine(DateTime.Now + str); } // Parse the information from message body. the information contains contains fields like test and xml try { string body = message.Body; JObject json = JObject.Parse(body); xml = (string)json.GetValue("xml"); test = (string)json.GetValue("test"); } // Catch exceptions while trying to create a JSON object catch (JsonException e) { Console.WriteLine(DateTime.Now + " " + e.Message); JSONCreated = false; } // Catch java.lang exceptions (trying to convert null to String) - make sure your message contains both those fields catch (Exception e) { Console.WriteLine(DateTime.Now + " " + e.Message); JSONCreated = false; } // If JSON object created successfully - continue if (JSONCreated) { ProcessNotification.process(test, xml); } // If JSON object wasn't created - ignore message else { String errorMessage = " Null or bad body in message id " + message.MessageId + ". Ignoring."; Console.WriteLine(DateTime.Now + errorMessage); } // Delete the message after all its information has been parsed queue.DeleteMessageAsync(queueUrl, ReceiptHandle); }
public void Process() { var client = new AmazonSQSClient(key, secret, region); var draining = true; // ignore messages from before startup while (true) { try { var resp = client.ReceiveMessage(uri); if (resp.Messages.Count == 0) { draining = false; } else { foreach (var m in resp.Messages) { if (!draining) // ignore messages sent while app closed { try { callback(m.Body); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } finally { try { client.DeleteMessage(uri, m.ReceiptHandle); } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } } } } } } catch (Exception ex) { Console.WriteLine($"ERROR: {ex.Message}"); } } }
static void Main(string[] args) { var accessKey = ConfigurationManager.AppSettings.Get("AccessKey"); var secretKey = ConfigurationManager.AppSettings.Get("SecretKey"); var queueName = "EmailQueue2"; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); IAmazonSQS amazonSQS = new AmazonSQSClient(credentials, RegionEndpoint.EUWest2); var queueUrl = amazonSQS.GetQueueUrlAsync(queueName).Result.QueueUrl; var receveMessagerequest = new ReceiveMessageRequest() { QueueUrl = queueUrl }; var receiveMessageResponse = amazonSQS.ReceiveMessageAsync(receveMessagerequest).Result; foreach (var message in receiveMessageResponse.Messages) { Console.WriteLine("Message \n"); Console.WriteLine($" MessageId: {message.MessageId} \n"); Console.WriteLine($" Receipthandle: {message.ReceiptHandle} \n"); Console.WriteLine($" MSD5Body: {message.MD5OfBody} \n"); Console.WriteLine($" Body: {message.Body} \n"); foreach (var attributes in message.Attributes) { Console.WriteLine("Attributes \n"); Console.WriteLine($" Name: {attributes.Key} \n"); Console.WriteLine($" Value: {attributes.Value} \n"); } var messageHandle = receiveMessageResponse.Messages.FirstOrDefault()?.ReceiptHandle; var deleteRequest = new DeleteMessageRequest { QueueUrl = queueUrl, ReceiptHandle = messageHandle }; Console.WriteLine($"deleting message with MessageHandle: {messageHandle}"); amazonSQS.DeleteMessageAsync(deleteRequest); Console.ReadLine(); } }
static void Main(string[] args) { const string queueUrl = "https://sqs.us-east-1.amazonaws.com/320502343338/SmartPlugQueue"; var config = new AmazonSQSConfig { ServiceURL = "http://sqs.us-east-1.amazonaws.com" }; var client = new AmazonSQSClient(config); var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = queueUrl, WaitTimeSeconds = 20 }; while (true) { Console.WriteLine("Waiting: "); var receiveMessageResponse = client.ReceiveMessage(receiveMessageRequest); foreach (var message in receiveMessageResponse.Messages) { string command = receiveMessageResponse.Messages.FirstOrDefault()?.Body; Console.WriteLine("Received: " + command); if (command == "ON") { string http = "http://10.0.0.136:3000/api/plug/turnallon/1"; using (var cli = new WebClient()) { cli.Headers.Add("content-type", "application/json"); cli.UploadString(http, "POST", ""); } } else if (command == "OFF") { string http = "http://10.0.0.136:3000/api/plug/turnalloff/1"; using (var cli = new WebClient()) { cli.Headers.Add("content-type", "application/json"); cli.UploadString(http, "POST", ""); } } client.DeleteMessage(new DeleteMessageRequest { QueueUrl = queueUrl, ReceiptHandle = message.ReceiptHandle }); } } }
static void Main(string[] args) { var num_messages = int.Parse(args[0]); var queue_url = args[1]; var ids = new int[] { 0, 0, 0, 0 }; System.Console.WriteLine($"Sending {num_messages} messages to SQS queue {queue_url}"); var sqs = new AmazonSQSClient(); //need keys and region var testMessage = new Faker <TestMessage>() .RuleFor(u => u.client_id, f => f.Random.Number(1, 4)) //"1") .RuleFor(u => u.id, (f, u) => ids[u.client_id - 1]++) .RuleFor(u => u.member_id, f => f.Random.Number(1, 1000000).ToString()) .FinishWith((f, u) => System.Console.WriteLine($"Message created for client_id {u.client_id}")); try { var messages = new List <TestMessage>(); for (int i = 0; i < num_messages; i++) { var message = testMessage.Generate(); messages.Add(message); if (messages.Count == 10) { var result = sqs.SendMessageBatchAsync(new SendMessageBatchRequest { QueueUrl = queue_url, Entries = messages.Select(x => new SendMessageBatchRequestEntry { Id = Guid.NewGuid().ToString(), MessageBody = JsonConvert.SerializeObject(x), MessageGroupId = x.client_id.ToString(), MessageAttributes = new Dictionary <string, MessageAttributeValue>() }).ToList() }).Result; if (result.Failed.Any()) { foreach (var entry in result.Failed) { System.Console.WriteLine($"Item {entry.Id} failed: {entry.Message}"); } } messages.Clear(); } } } catch (System.Exception) { throw; } }
public static GlacierResult ProcessQueue(Topic topic) { // Check for notifications on topic and process any message try { var settings = SettingsManager.GetSettings(); using (var client = new AmazonGlacierClient( settings.AWSAccessKeyID, settings.AWSSecretAccessKey, RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName))) { var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = topic.QueueUrl, MaxNumberOfMessages = 1 }; var sqsClient = new AmazonSQSClient(settings.AWSAccessKeyID, settings.AWSSecretAccessKey, RegionEndpoint.GetBySystemName(settings.AWSS3Region.SystemName)); var receiveMessageResponse = sqsClient.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.Messages.Count == 0) { return(GlacierResult.Incomplete); } // Process message string status = GetResponseStatus(receiveMessageResponse); if (string.Equals(status, GlacierUtils.JOB_STATUS_SUCCEEDED, StringComparison.InvariantCultureIgnoreCase)) { FileManager.DownloadGlacierJobOutput(topic.JobId, client, settings.AWSGlacierVault, topic.GetOutputFile()); Debug.WriteLine($"Downloaded job output to {topic.GetOutputFile()}"); return(GlacierResult.Completed); } else if (string.Equals(status, GlacierUtils.JOB_STATUS_FAILED, StringComparison.InvariantCultureIgnoreCase)) { return(GlacierResult.JobFailed); } else if (string.Equals(status, GlacierUtils.JOB_STATUS_INPROGRESS, StringComparison.InvariantCultureIgnoreCase)) { return(GlacierResult.JobInProgress); } else { return(GlacierResult.Error); } } } catch (AmazonServiceException azex) { Debug.WriteLine("AmazonServiceException " + azex.Message); throw azex; } }
private static async Task SetupAws() { try { Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", "XXX", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", "XXX", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("AWS_SESSION_TOKEN", "XXX", EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("AWS_DEFAULT_REGION", "us-east-1", EnvironmentVariableTarget.Process); var snsClient = new AmazonSimpleNotificationServiceClient(new AmazonSimpleNotificationServiceConfig { ServiceURL = "http://localhost:4575" }); var sqsClient = new AmazonSQSClient(new AmazonSQSConfig { ServiceURL = "http://localhost:4576" }); var topicName = topic.Replace(".", "_"); var topicRequest = new CreateTopicRequest(topicName); var topicResponse = await snsClient.CreateTopicAsync(topicRequest); var queueRequest = new CreateQueueRequest($"{topicName}.queue"); var queueResponse = await sqsClient.CreateQueueAsync(queueRequest); var subscribeRequest = new SubscribeRequest { Endpoint = queueResponse.QueueUrl, TopicArn = topicResponse.TopicArn, Protocol = "sqs", ReturnSubscriptionArn = true, Attributes = new Dictionary <string, string> { ["RawMessageDelivery"] = "true" } }; var subscribeResponse = await snsClient.SubscribeAsync(subscribeRequest); (await snsClient.ListTopicsAsync()).Topics.ForEach(x => Console.WriteLine($"[AWS] Topic: {x.TopicArn}")); (await sqsClient.ListQueuesAsync(new ListQueuesRequest())).QueueUrls.ForEach(x => Console.WriteLine($"[AWS] Queue: {x}")); (await snsClient.ListSubscriptionsAsync(new ListSubscriptionsRequest())).Subscriptions.ForEach(x => Console.WriteLine($"[AWS] Subscription: {x.TopicArn} -> {x.Endpoint}")); } catch (Exception e) { Console.WriteLine($"[AWS] {e.Message}"); } }
public static int QueueLengthByQueueUrl(string queueUrl) { using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret)) { var request = new GetQueueAttributesRequest { QueueUrl = queueUrl, AttributeNames = new List <string> { "ApproximateNumberOfMessages" } }; return(client.GetQueueAttributes(request).ApproximateNumberOfMessages); } }
public override async Task SaveStat(string word, TimeSpan time) { this._logger?.Information("Try queue"); using var sqsCli = new AmazonSQSClient(); var queueUrl = await sqsCli.GetQueueUrlAsync(new GetQueueUrlRequest("profanity-stat-queue")); var aa = await sqsCli.SendMessageAsync(new SendMessageRequest { QueueUrl = queueUrl.QueueUrl, MessageBody = "Try " + word }); this._logger?.Information(aa.MessageId); }
protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { _sqsClient.Dispose(); _sqsClient = null; _snsClient.Dispose(); _snsClient = null; } _disposed = true; } }
public CartRepository( ILogger <CartRepository> logger, IMapper mapper, IMongoCollection <Entities.Cart> cartsCollection, IProductService productService, AmazonSQSClient amazonSQSClient, IConfiguration configuration) { _logger = logger; _mapper = mapper; _cartsCollection = cartsCollection; _productService = productService; _amazonSQSClient = amazonSQSClient; _configuration = configuration; }
private AmazonSQSClient CreateClient(SqsConfiguration configuration) { if (_sqsClient == null) { _sqsClient = string.IsNullOrEmpty(configuration.AccessKey) ? new AmazonSQSClient(new AmazonSQSConfig { RegionEndpoint = RegionEndpoint.GetBySystemName(configuration.Region) }) : new AmazonSQSClient(new BasicAWSCredentials(configuration.AccessKey, configuration.SecretKey), RegionEndpoint.GetBySystemName(configuration.Region)); } return(_sqsClient); }