Now that you've confirmed your queue exists in the Amazon SQS system, you can send a message to the
queue. The following code snippets demonstrate how to send the message This is my message
text. to your MyQueue queue.
To run the sample
Open SendMessageSample.java.
Locate the following lines.
SendMessageRequest request = new SendMessageRequest();
// @TODO: set request parameters here
// invokeSendMessage(service, request);Replace the lines with the following new lines of code.
SendMessageRequest request = new SendMessageRequest();
request.setQueueName("MyQueue");
request.setMessageBody("This is my message text.");
invokeSendMessage(service, request);Compile and run the sample.
The message This is my message text. is sent to the queue. The response includes the following items:
The message ID Amazon SQS assigns to the message
An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)
The request ID that Amazon SQS assigned to your request
To run the sample
Open AmazonSQSSamples.cs.
Comment out the code you added in the preceding section (that code consisted of the following lines).
ListQueuesRequest request = new ListQueuesRequest(); ListQueuesSample.InvokeListQueues(service, request);
Locate the following lines.
// SendMessageRequest request = new SendMessageRequest(); // @TODO: set request parameters here // SendMessageSample.InvokeSendMessage(service, request);
Replace the lines with the following new lines of code.
SendMessageRequest request = new SendMessageRequest(); request.QueueName = "MyQueue"; request.MessageBody = "This is my message text."; SendMessageSample.InvokeSendMessage(service, request);
Run the sample.
The message This is my message text. is sent to the queue. The response includes the following items:
The message ID Amazon SQS assigns to the message
An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)
The request ID that Amazon SQS assigned to your request
To run the sample
Open SendMessageSample.pl.
Locate the following line.
# invokeSendMessage($service, $request);
Replace the line with the following new lines of code.
my $request = Amazon::SQS::Model::SendMessageRequest->new({
QueueName => "MyQueue",
MessageBody => "This is my message text."
});
invokeSendMessage($service, $request);Run the sample.
The message This is my message text. is sent to the queue. The response includes the following items:
The message ID Amazon SQS assigns to the message
An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)
The request ID that Amazon SQS assigned to your request
To run the sample
Open SendMessageSample.php.
Locate the following line.
// invokeSendMessage($service, $request);
Replace the line with the following new lines of code.
require_once ('Amazon/SQS/Model/SendMessageRequest.php');
$request = new Amazon_SQS_Model_SendMessageRequest();
$request->setQueueName('MyQueue');
$request->setMessageBody('This is my message text.');
invokeSendMessage($service, $request);Run the sample.
The message This is my message text. is sent to the queue. The response includes the following items:
The message ID Amazon SQS assigns to the message
An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)
The request ID that Amazon SQS assigned to your request
To run the sample
Open AmazonSQSSamples.vb.
Comment out the code you added in the preceding section (that code consisted of the following lines).
Dim request As New ListQueuesRequest() ListQueuesSample.InvokeListQueues(service, request)
Locate the following lines.
' Dim request As New SendMessageRequest() ' @TODO: set request parameters here ' SendMessageSample.InvokeSendMessage(service, request)
Replace the lines with the following new lines of code.
Dim request As New SendMessageRequest() request.QueueName = "MyQueue" request.MessageBody = "This is my message text." SendMessageSample.InvokeSendMessage(service, request)
Run the sample.
The message This is my message text. is sent to the queue. The response includes the following items:
The message ID Amazon SQS assigns to the message
An MD5 digest of the message body, which you can use to confirm that SQS received the message correctly (for information about MD5, go to http://faqs.org/rfcs/rfc1321.html)
The request ID that Amazon SQS assigned to your request
To run the sample
In the scratchpad, select SendMessage from the Explore API list box.
Enter MyQueue in the Queue Name field.
Enter This is my message text. in the Message Body
field.
Select one of the following:
To invoke the request, click Invoke Request. Amazon SQS returns a response.
To view the signed URL, click Display Signed URL. Then, copy and paste the signed URL into a browser. Amazon SQS returns a response.
To view the string to sign, click Display String to Sign.