Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting..");

            string sQueue = "https://sqs.eu-west-1.amazonaws.com/{CODE}/{QUEUENAME}"; // Region / CODE and QueueName

            try
            {
                var config = new AmazonSQSConfig()
                {
                    ServiceURL = "https://sqs.eu-west-1.amazonaws.com/" // Region and URL
                };

                var _messageRequest = new SendMessageRequest();

                _messageRequest.QueueUrl = sQueue;

                _messageRequest.MessageBody = "This is a test message";

                AmazonSQSClient _client = new AmazonSQSClient("ACCESSKEY", "ACCESSSECRET", config);

                SendMessageResponse sendMessageResponse = _client.SendMessage(_messageRequest);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.ToString());
            }

            Console.WriteLine("Complete");
        }
Exemplo n.º 2
0
        public static void Send <T>(string sQueueName, T payLoad)
        {
            AmazonSQSClient sqs      = new AmazonSQSClient();
            string          sPayload = JsonConvert.SerializeObject(payLoad);

            sqs.SendMessage(GetQueue(sqs, sQueueName), sPayload);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Requeues the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="delayMilliseconds">Number of milliseconds to delay delivery of the message.</param>
        public void Requeue(Message message, int delayMilliseconds)
        {
            try
            {
                Reject(message, false);

                using (var client = new AmazonSQSClient())
                {
                    _logger.InfoFormat("SqsMessageConsumer: requeueing the message {0}", message.Id);

                    message.Header.Bag.Remove("ReceiptHandle");
                    var request = new SendMessageRequest(_queueUrl, JsonConvert.SerializeObject(message))
                    {
                        DelaySeconds = (int)TimeSpan.FromMilliseconds(delayMilliseconds).TotalSeconds
                    };

                    client.SendMessage(request);
                }

                _logger.InfoFormat("SqsMessageConsumer: requeued the message {0}", message.Id);
            }
            catch (Exception exception)
            {
                _logger.ErrorException("SqsMessageConsumer: Error purging queue {0}", exception, _queueUrl);
                throw;
            }
        }
Exemplo n.º 4
0
        public void SendMssageExample()
        {
            AmazonSQSClient client = new AmazonSQSClient();

            var sendMessageRequest = new SendMessageRequest
            {
                DelaySeconds      = 10,
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "Title", new MessageAttributeValue {
                          DataType = "String", StringValue = "The Whistler"
                      } },
                    { "Author", new MessageAttributeValue {
                          DataType = "String", StringValue = "John Grisham"
                      } },
                    { "WeeksOn", new MessageAttributeValue {
                          DataType = "Number", StringValue = "6"
                      } }
                },
                MessageBody = "Information about current NY Times fiction bestseller for week of 12/11/2016.",
                QueueUrl    = "SQS_QUEUE_URL"
            };

            var response = client.SendMessage(sendMessageRequest);

            Console.WriteLine("Sent a message with id : {0}", response.MessageId);
        }
Exemplo n.º 5
0
        protected void btnSendMessage_Click(object sender, EventArgs e)
        {
            if (QueuesList.SelectedIndex > -1)
            {
                if (!string.IsNullOrEmpty(txtMessage.Text))
                {
                    string selectedQueue = this.QueuesList.SelectedItem.Value.ToString();

                    objClient.SendMessage(new SendMessageRequest()
                    {
                        MessageBody = this.txtMessage.Text, QueueUrl = selectedQueue
                    });

                    Response.Write("<script>alert('Message sent successfully to Queue.');</script>");
                }
                else
                {
                    Response.Write("<script>alert('Please enter Message Text.');</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Please select Queue from list.');</script>");
            }
        }
Exemplo n.º 6
0
        private static void SendMessagesWithInjectedHeaders(AmazonSQSClient sqsClient)
        {
            // Send one message, receive it, and parse it for its headers
            sqsClient.SendMessage(_singleQueueUrl, "SendMessageAsync_SendMessageRequest");

            var receiveMessageRequest = new ReceiveMessageRequest()
            {
                QueueUrl = _singleQueueUrl,
                MessageAttributeNames = new List <string>()
                {
                    ".*"
                }
            };
            var receiveMessageResponse1 = sqsClient.ReceiveMessage(receiveMessageRequest);

            sqsClient.DeleteMessage(_singleQueueUrl, receiveMessageResponse1.Messages.First().ReceiptHandle);
            Common.AssertDistributedTracingHeaders(receiveMessageResponse1.Messages);

            // Send a batch of messages, receive them, and parse them for headers
            var sendMessageBatchRequest = new SendMessageBatchRequest
            {
                Entries = new List <SendMessageBatchRequestEntry>
                {
                    new("message1", "SendMessageBatchAsync: FirstMessageContent"),
                    new("message2", "SendMessageBatchAsync: SecondMessageContent"),
                    new("message3", "SendMessageBatchAsync: ThirdMessageContent")
                },
Exemplo n.º 7
0
        public void SendMessages(AmazonSQSClient client, string url, string sendMessage, int delaySecond)
        {
            var message = new SendMessageRequest()
            {
                MessageBody       = sendMessage,
                DelaySeconds      = delaySecond,
                QueueUrl          = url,
                MessageAttributes = new Dictionary <string, MessageAttributeValue>
                {
                    { "DayAttribute", new MessageAttributeValue {
                          DataType = "String", StringValue = "Monday"
                      } },
                    { "TempretureAttribute", new MessageAttributeValue {
                          DataType = "String", StringValue = "Hot 33"
                      } },
                    { "WeatherAttribute", new MessageAttributeValue {
                          DataType = "String", StringValue = "Cloudy with channce of Thunderstorm"
                      } },
                }
            };

            var response = client.SendMessage(message);

            Console.WriteLine("---Sent Message attributes---- " + response.MD5OfMessageAttributes);
            Console.WriteLine("---Sent Message Body---- " + response.MD5OfMessageBody);
            Console.WriteLine("---Sent Message Id---- " + response.MessageId);
        }
Exemplo n.º 8
0
        public void send_and_recieve_messages()
        {
            Console.WriteLine("Sending Message");
            var sendMessageRequest = new SendMessageRequest()
                                     .WithQueueUrl(_queueUrl)
                                     .WithMessageBody("Hello from the cloud");

            var sendResult = _client.SendMessage(sendMessageRequest);

            Console.WriteLine(sendResult.ToXML());

            Console.WriteLine("Receiving Message");
            var request =
                new ReceiveMessageRequest().
                WithQueueUrl(_queueUrl);

            var result = _client.ReceiveMessage(request);

            foreach (var message in result.ReceiveMessageResult.Message)
            {
                Console.WriteLine(message.Body);
                _client.DeleteMessage(
                    new DeleteMessageRequest().WithQueueUrl(_queueUrl).WithReceiptHandle(message.ReceiptHandle));
            }
        }
Exemplo n.º 9
0
        public void SendMessage(string jsonBody, bool deduplicate = false)
        {
            var sendMessageRequest = new SendMessageRequest
            {
                QueueUrl       = queueUrl,
                MessageBody    = jsonBody,
                MessageGroupId = "{MessageGroupId}"
            };

            if (deduplicate)
            {
                var unixTimestamp = DateTime.Now.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;

                var stringToHash = jsonBody + unixTimestamp;
                var bytes        = Encoding.UTF8.GetBytes(stringToHash);
                using (var sha512 = new SHA512Managed())
                {
                    var hashBytes = sha512.ComputeHash(bytes);
                    var result    = Convert.ToBase64String(hashBytes);
                    sendMessageRequest.MessageDeduplicationId = result;
                }
            }

            var response = sqsClient.SendMessage(sendMessageRequest);

            if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("Error sending request");
            }
        }
Exemplo n.º 10
0
        public void Send(msg.Message message)
        {
            var request = new SendMessageRequest();

            request.QueueUrl    = QueueUrl;
            request.MessageBody = msg.AwsMessage.Wrap(message);
            _sqsClient.SendMessage(request);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Sends a message using the metadata in the envelope if applicable
        /// </summary>
        /// <param name="message"></param>
        public void Send(Envelope <Stream> message)
        {
            SendMessageRequest msgRequest = AmazonSQSMessageConverter.ConstructMessage(message);

            msgRequest.QueueUrl = QueueName;

            _client.SendMessage(msgRequest);
        }
Exemplo n.º 12
0
        void sendMessage(string message)
        {
            var request = new SendMessageRequest();

            request.QueueUrl    = queueUrl;
            request.MessageBody = message;
            client.SendMessage(request);
        }
Exemplo n.º 13
0
        private static void SendMessageToOutputQueue(MessageEntity message, string outputQueueURL, AmazonSQSClient client)
        {
            message.message = "reply_message";
            string              outputMessage       = JsonConvert.SerializeObject(message);
            SendMessageRequest  sendMessageRequest  = new SendMessageRequest(outputQueueURL, outputMessage);
            SendMessageResponse sendMessageResponse = client.SendMessage(sendMessageRequest);

            Console.WriteLine("Message sent succesfully");
        }
Exemplo n.º 14
0
        static void WriteToQueue(AWSCredentials credentials)
        {
            AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);

            string message  = "my message";
            string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";

            SendMessageResponse sendMessageResponse = client.SendMessage(queueUrl, message);
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            try
            {
                var client = new AmazonSQSClient();

                // List all queues that start with "aws".
                var request = new ListQueuesRequest
                {
                    QueueNamePrefix = "CitizensQueue"
                };

                var response = client.ListQueues(request);
                var urls     = response.QueueUrls;

                if (urls.Any())
                {
                    Console.WriteLine("Queue URLs:");

                    foreach (var url in urls)
                    {
                        Console.WriteLine("  " + url);
                    }
                }
                else
                {
                    Console.WriteLine("No queues.");
                }

                //this is the interface to SQS Service
                AmazonSQSClient SQSClient = new AmazonSQSClient();

                //create the message object
                SendMessageRequest MessageRequest = new SendMessageRequest();

                //read this URL from the AWS SQS console
                MessageRequest.QueueUrl = "your queue URL";

                //set the message text
                MessageRequest.MessageBody = "This is a test";

                //send the message
                SQSClient.SendMessage(MessageRequest);

                //prevent the console window from closing
                Console.ReadLine();
            }

            catch (Exception ex)
            {
                //display exception
                Console.WriteLine(ex.Message);
                //prevent the console window from closing
                Console.ReadLine();
            }
        }
Exemplo n.º 16
0
        public void Send <T>(T message)
        {
            var formattedMessage = _messageFormatter.Write(message);

            var messageRequest = new SendMessageRequest()
                                 .WithQueueUrl(_uri)
                                 .WithMessageBody(formattedMessage);

            _client.SendMessage(messageRequest);
        }
Exemplo n.º 17
0
        public void SubmitJobAsTestModel(string testModelAsString)
        {
            AmazonSQSClient amazonSqsClient = new AmazonSQSClient(ConfigurationManager.AppSettings["accessKeyID"],ConfigurationManager.AppSettings["secretAccessKeyID"], RegionEndpoint.EUWest1);

            var queue = amazonSqsClient.GetQueueUrl("EgAutomatedTests");

            var mod = JsonConvert.DeserializeObject<TestModel>(testModelAsString);

            amazonSqsClient.SendMessage(queue.QueueUrl, JsonConvert.SerializeObject(mod));
        }
Exemplo n.º 18
0
        public static void SendMessage(AmazonSQSClient _sqs,
                                       string _queueUrl,
                                       TGSerializedObject _tgs)
        {
            SendMessageRequest request = new SendMessageRequest {
                QueueUrl = _queueUrl, MessageBody = _tgs.ToString()
            };

            _sqs.SendMessage(request);
        }
Exemplo n.º 19
0
        static void Main(string[] args)
        {
            try
            {
                // create SQS client
                var sqsConfig = new AmazonSQSConfig()
                {
                    ServiceURL = "https://sqs.us-east-1.amazonaws.com"
                };

                Console.WriteLine("Creating AWS SQSClient");
                var sqsClient = new AmazonSQSClient(sqsConfig);

                if (useFIFO)
                {
                    Dictionary <String, String> dictSQSAttribute = new Dictionary <string, string>();
                    {
                        dictSQSAttribute.Add("ContentBasedDeduplication", "true");
                    }
                    sqsClient.SetQueueAttributes(SQS_URL, dictSQSAttribute);
                }
                Console.WriteLine("Creating AWS SQSClient done");


                // start loop to send message
                int      count   = 0;
                DateTime dtStart = DateTime.Now;
                int      msgId   = 0;
                while ((DateTime.Now - dtStart).TotalSeconds < RUN_PERIOD_SECOND)
                {
                    // create sendMessageRequest message
                    SendMessageRequest sendMessageRequest = new SendMessageRequest();
                    {
                        String id = DateTime.Now.Hour + DateTime.Now.Minute + "." + ++msgId;
                        sendMessageRequest.QueueUrl    = SQS_URL;
                        sendMessageRequest.MessageBody = "[" + id + "] Message from C# application at " + DateTime.Now.ToString();

                        if (useFIFO)
                        {
                            sendMessageRequest.MessageGroupId = (msgId % SQS_FIFO_NUMBER_OF_GROUP).ToString();
                        }
                    }

                    // send message
                    sqsClient.SendMessage(sendMessageRequest);

                    Console.WriteLine("Publish SQS message {0}", ++count);
                }
                Console.WriteLine("Publish SQS message done");
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: " + e.ToString());
            }
        }
Exemplo n.º 20
0
        private void AddToQueue(string data)
        {
            var sendMessageRequest = new SendMessageRequest
            {
                QueueUrl    = QueueUrl,
                MessageBody = data
            };
            var response = _sqsClient.SendMessage(sendMessageRequest);

            Console.WriteLine("Response status code: " + response.HttpStatusCode);
        }
Exemplo n.º 21
0
        public void Send(object value)
        {
            string data    = _dataSerializer.ToJson(value);
            var    request = new SendMessageRequest
            {
                QueueUrl    = _config.QueueUrl,
                MessageBody = data
            };

            _client.SendMessage(request);
        }
Exemplo n.º 22
0
        public virtual void PostToQueue(AmazonSQSClient sqsClient, string queueUrl, string messageText)
        {
            // Create the request
            var sendMessageRequest = new SendMessageRequest
            {
                MessageBody = messageText,
                QueueUrl    = queueUrl
            };

            //Send message to queue
            sqsClient.SendMessage(sendMessageRequest);
        }
Exemplo n.º 23
0
        public void SendMessage()
        {
            SendMessageRequest request = new SendMessageRequest {
                QueueUrl = QueueUrl, MessageBody = "My Queue Message"
            };
            var response = client.SendMessage(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine("Message Sent Successfully");
                Console.WriteLine($"Message Id: {response.MessageId}, Sequence Id: {response.SequenceNumber}");
            }
        }
Exemplo n.º 24
0
        public static void EnqueueByQueueUrl(string queueUrl, string message)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var request = new SendMessageRequest()
                {
                    QueueUrl    = queueUrl,
                    MessageBody = message,
                };

                client.SendMessage(request);
            }
        }
Exemplo n.º 25
0
 public void SendMessage(MessagePumpModel message)
 {
     try
     {
         logger.Debug("Sending message: {0} - {1}", message.Id, message.Message);
         SendMessageRequest  request  = new SendMessageRequest(QUEUE_URL, JsonConvert.SerializeObject(message));
         SendMessageResponse response = _client.SendMessage(request);
         logger.Debug("Message sent with status code: {0}", response.HttpStatusCode);
     }
     catch (Exception ex)
     {
         logger.Error("Send message failed: {0}", ex.ToString());
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// Send message on named queue with a visibility delay.
        /// </summary>
        /// <param name="queueName">Queue name.</param>
        /// <param name="messageBody">Message body.</param>
        /// <param name="delay">Time to wait until the message becomes visible.</param>
        public void SendMessage(SqsQueueName queueName, string messageBody, TimeSpan delay)
        {
            var response = Invoke(() =>
                                  _client.SendMessage(new SendMessageRequest {
                QueueUrl          = GetQueueUrl(queueName.Value),
                MessageBody       = messageBody,
                DelaySeconds      = (int)delay.TotalSeconds,
                MessageAttributes = GetQueueNameAttribute(queueName.Value)
            }),
                                  queueName,
                                  SENDING_MESSAGE);

            AssertSuccessfulStatusCode(response.HttpStatusCode, queueName, SENDING_MESSAGE);
        }
Exemplo n.º 27
0
        private static void SendToQueue()
        {
            Console.WriteLine("Type a message for the queue, <return> to submit.");
            string message = Console.ReadLine();

            var request = new SendMessageRequest()
            {
                QueueUrl    = QUEUE_URL,
                MessageBody = message
            };
            var response = client.SendMessage(request);

            Console.WriteLine("Response code: " + response.HttpStatusCode.ToString());
        }
Exemplo n.º 28
0
 public void SendMessage(TenantActionMessage message)
 {
     try
     {
         var sendMessageRequest = new SendMessageRequest();
         sendMessageRequest.QueueUrl    = awsSqsConfiguration.QueueURL;
         sendMessageRequest.MessageBody = JsonConvert.SerializeObject(message);
         var sendMessageResponse = amazonSQSClient.SendMessage(sendMessageRequest);
         Console.WriteLine($"Send message successful : " + sendMessageResponse.ToString());
     }
     catch (Exception ex)
     {
         Console.WriteLine("Error: " + ex.ToString());
     }
 }
        public void SendMessage()
        {
            SendMessageRequest request = new SendMessageRequest
            {
                QueueUrl    = "https://sqs.us-east-1.amazonaws.com/491483104165/newappqueue",
                MessageBody = "Message Queue Body"
            };

            var response = client.SendMessage(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine($"Message Sent Successfully! \nMessageId: {response.MessageId}");
            }
        }
Exemplo n.º 30
0
        public static void EnqueueListByQueueUrl(string queueUrl, IEnumerable <string> messages)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                foreach (var message in messages)
                {
                    var request = new SendMessageRequest()
                    {
                        QueueUrl    = queueUrl,
                        MessageBody = message,
                    };

                    client.SendMessage(request);
                }
            }
        }