SendMessage() public method

Delivers a message to the specified queue.

The following list shows the characters (in Unicode) that are allowed in your message, according to the W3C XML specification:

  • #x9

  • #xA

  • #xD

  • #x20 to #xD7FF

  • #xE000 to #xFFFD

  • #x10000 to #x10FFFF

For more information, see RFC1321. If you send any characters that aren't included in this list, your request is rejected.

/// The message contains characters outside the allowed set. /// /// Error code 400. Unsupported operation. ///
public SendMessage ( SendMessageRequest request ) : SendMessageResponse
request Amazon.SQS.Model.SendMessageRequest Container for the necessary parameters to execute the SendMessage service method.
return Amazon.SQS.Model.SendMessageResponse
Ejemplo n.º 1
1
        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);
        }
Ejemplo n.º 2
1
 public bool sendPosition(string latitude, string longitude)
 {
     AmazonSQSClient sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USEast1);
     Amazon.SQS.Model.SendMessageRequest request = new Amazon.SQS.Model.SendMessageRequest();
     request.QueueUrl = SQS_URL_STRING;
     request.MessageBody = "lat: " + latitude + " lon: " + longitude;
     sqsClient.SendMessage(request);
     return true;
 }
Ejemplo n.º 3
1
		public SqsActor ()
		{
			Receive<string> (x => {


                var sqs_url = Environment.GetEnvironmentVariable("sqs_url", EnvironmentVariableTarget.Process);
                var config = new AmazonSQSConfig();
                config.ServiceURL = sqs_url;

                var creds = new StoredProfileAWSCredentials();
                var client = new AmazonSQSClient(creds, config);

                var msg =  x + " and what " + Guid.NewGuid().ToString();
                var queue_url = Environment.GetEnvironmentVariable("queue_url", EnvironmentVariableTarget.Process);
             
                var request = new Amazon.SQS.Model.SendMessageRequest(queue_url, msg);
             
                client.SendMessage(request);

				Sender.Tell(string.Format("done  : [{0}]", msg ));
			});
		}
Ejemplo n.º 4
0
    public static void SQSSendMessage()
    {
      #region SQSSendMessage
      var client = new AmazonSQSClient();

      var request = new SendMessageRequest
      {
        DelaySeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds,
        MessageAttributes = new Dictionary<string, MessageAttributeValue>
        {
          {
            "MyNameAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "John Doe" }
          },
          {
            "MyAddressAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "123 Main St." }
          },
          {
            "MyRegionAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "Any Town, United States" }
          }
        },
        MessageBody = "John Doe customer information.",
        QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue"
      };

      var response = client.SendMessage(request);

      Console.WriteLine("For message ID '" + response.MessageId + "':");
      Console.WriteLine("  MD5 of message attributes: " +
        response.MD5OfMessageAttributes);
      Console.WriteLine("  MD5 of message body: " + response.MD5OfMessageBody);
      #endregion

      Console.ReadLine();
    }
        // POST /api/echo
        public void Post(string message)
        {
            // AWS: Get instance public address
            string myAddress = HttpContext.Current.Request.Url.Authority;
            try
            {
                myAddress = Encoding.ASCII.GetString(new WebClient().DownloadData("http://169.254.169.254/latest/meta-data/public-hostname"));
            }
            catch
            {
            }

            var messageJob = new JsonObject();
            messageJob["message"] = message;
            messageJob["sender"] = myAddress;

            // AWS SQS Client
            var sqsClient = new AmazonSQSClient();

            SendMessageRequest request = new SendMessageRequest()
                .WithQueueUrl("https://queue.amazonaws.com/******/codeCampDemo")
                .WithMessageBody(messageJob.ToString());
            sqsClient.SendMessage(request);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public static void Main(string[] args)
        {
            IAmazonSQS sqs = new AmazonSQSClient(RegionEndpoint.USWest2);

            try
            {
                Console.WriteLine("===========================================");
                Console.WriteLine("Getting Started with Amazon SQS");
                Console.WriteLine("===========================================\n");                
                
                //Creating a queue
                Console.WriteLine("Create a queue called MyQueue.\n");
                CreateQueueRequest sqsRequest = new CreateQueueRequest();
                sqsRequest.QueueName = "MyQueue";
                CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest);
                String myQueueUrl;
                myQueueUrl = createQueueResponse.QueueUrl;

                //Confirming the queue exists
                ListQueuesRequest listQueuesRequest = new ListQueuesRequest();
                ListQueuesResponse listQueuesResponse = sqs.ListQueues(listQueuesRequest);

                Console.WriteLine("Printing list of Amazon SQS queues.\n");
                foreach (String queueUrl in listQueuesResponse.QueueUrls)
                {
                    Console.WriteLine("  QueueUrl: {0}", queueUrl);
                }
                Console.WriteLine();

                //Sending a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                SendMessageRequest sendMessageRequest = new SendMessageRequest();
                sendMessageRequest.QueueUrl = myQueueUrl; //URL from initial queue creation
                sendMessageRequest.MessageBody = "This is my message text.";
                sqs.SendMessage(sendMessageRequest);
                
                //Receiving a message
                ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
                receiveMessageRequest.QueueUrl = myQueueUrl;
                ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);

                Console.WriteLine("Printing received message.\n");
                foreach (Message message in receiveMessageResponse.Messages)
                {
                    Console.WriteLine("  Message");
                    Console.WriteLine("    MessageId: {0}", message.MessageId);
                    Console.WriteLine("    ReceiptHandle: {0}", message.ReceiptHandle);
                    Console.WriteLine("    MD5OfBody: {0}", message.MD5OfBody);
                    Console.WriteLine("    Body: {0}", message.Body);

                    foreach (KeyValuePair<string, string> entry in message.Attributes)
                    {
                        Console.WriteLine("  Attribute");
                        Console.WriteLine("    Name: {0}", entry.Key);
                        Console.WriteLine("    Value: {0}", entry.Value);
                    }
                }
                String messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;

                //Deleting a message
                Console.WriteLine("Deleting the message.\n");
                DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
                deleteRequest.QueueUrl = myQueueUrl;
                deleteRequest.ReceiptHandle = messageRecieptHandle;
                sqs.DeleteMessage(deleteRequest);

            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }

            Console.WriteLine("Press Enter to continue...");
            Console.Read();
        }
Ejemplo n.º 8
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;
            }
        }
Ejemplo n.º 9
0
        public static void Main(string[] args)
        {
            var sqs = new AmazonSQSClient();

            try
            {
                Console.WriteLine("===========================================");
                Console.WriteLine("Getting Started with Amazon SQS");
                Console.WriteLine("===========================================\n");

                //Confirming the queue exists
                var listQueuesRequest = new ListQueuesRequest();
                var listQueuesResponse = sqs.ListQueues(listQueuesRequest);
                string myQueueUrl = string.Empty;

                Console.WriteLine("Printing list of Amazon SQS queues.\n");
                bool queueExists = false;
                if (listQueuesResponse.QueueUrls != null)
                {
                    foreach (String queueUrl in listQueuesResponse.QueueUrls)
                    {
                        Console.WriteLine("  QueueUrl: {0}", queueUrl);
                        if (queueUrl.EndsWith("MyQueue"))
                        {
                            queueExists = true;
                            myQueueUrl = queueUrl;
                            break;
                        }
                    }
                }
                Console.WriteLine();

                if (!queueExists)
                {
                    //Creating a queue
                    Console.WriteLine("Create a queue called MyQueue.\n");
                    var sqsRequest = new CreateQueueRequest { QueueName = "MyQueue" };
                    var createQueueResponse = sqs.CreateQueue(sqsRequest);
                    myQueueUrl = createQueueResponse.QueueUrl;
                }

                //Sending a message
                Console.WriteLine("Sending a message to MyQueue.\n");
                var sendMessageRequest = new SendMessageRequest
                    {
                        QueueUrl = myQueueUrl, //URL from initial queue creation
                        MessageBody = string.Format("ATL MEETUP - This is my message text from server - {0}",System.Environment.MachineName)
                    };
                sqs.SendMessage(sendMessageRequest);

                ////Receiving a message
                //var receiveMessageRequest = new ReceiveMessageRequest { QueueUrl = myQueueUrl };
                //var receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
                //if (receiveMessageResponse.Messages != null)
                //{
                //    Console.WriteLine("Printing received message.\n");
                //    foreach (var message in receiveMessageResponse.Messages)
                //    {
                //        Console.WriteLine("  Message");
                //        if (!string.IsNullOrEmpty(message.MessageId))
                //        {
                //            Console.WriteLine("    MessageId: {0}", message.MessageId);
                //        }
                //        if (!string.IsNullOrEmpty(message.ReceiptHandle))
                //        {
                //            Console.WriteLine("    ReceiptHandle: {0}", message.ReceiptHandle);
                //        }
                //        if (!string.IsNullOrEmpty(message.MD5OfBody))
                //        {
                //            Console.WriteLine("    MD5OfBody: {0}", message.MD5OfBody);
                //        }
                //        if (!string.IsNullOrEmpty(message.Body))
                //        {
                //            Console.WriteLine("    Body: {0}", message.Body);
                //        }

                //        foreach (string attributeKey in message.Attributes.Keys)
                //        {
                //            Console.WriteLine("  Attribute");
                //            Console.WriteLine("    Name: {0}", attributeKey);
                //            var value = message.Attributes[attributeKey];
                //            Console.WriteLine("    Value: {0}", string.IsNullOrEmpty(value) ? "(no value)" : value);
                //        }
                //    }

                //    var messageRecieptHandle = receiveMessageResponse.Messages[0].ReceiptHandle;

                //    //Deleting a message
                //    Console.WriteLine("Deleting the message.\n");
                //    var deleteRequest = new DeleteMessageRequest { QueueUrl = myQueueUrl, ReceiptHandle = messageRecieptHandle };
                //    sqs.DeleteMessage(deleteRequest);
                //}

            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }

            Console.WriteLine("Press Enter to continue...");
            Console.Read();
        }
Ejemplo n.º 10
0
 private static String QueueMessage()
 {
     using (AmazonSQSClient client = new AmazonSQSClient(
        ConfigurationManager.AppSettings["AWSAccessKey"],
        ConfigurationManager.AppSettings["AWSSecretAccessKey"]))
     {
         SendMessageRequest request = new SendMessageRequest();
         request.MessageBody = Guid.NewGuid().ToString();
         request.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
         SendMessageResponse response = client.SendMessage(request);
         return response.SendMessageResult.MessageId;
     }
 }
Ejemplo n.º 11
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);
            }
        }
Ejemplo n.º 12
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);
                }
            }
        }