Create Queue:
CreateQueueRequest createQueueRequest = new CreateQueueRequest(name);
CreateQueueResponse createQueueResponse = queueClient.createQueue(
createQueueRequest);
// All later actions require the use of the queueName created here, and not the name in the first line
String queueName = createQueueResponse.getQueueName();
Sender:
while(true) {
SendMessageRequest sendMessageRequest =
new SendMessageRequest(queueName, messageBody);
SendMessageResponse sendMessageResponse =
messageClient.sendMessage(sendMessageRequest);
}
Receiver:
while(true) {
ReceiveMessageRequest receiveMessageRequest =
new ReceiveMessageRequest(queueName);
List<ReceiveMessageResponse> receiveMessageResponse =
messageClient.receiveMessage(receiveMessageRequest);
if (!receiveMessageResponse.isEmpty()) {
// process receiveMessageResponse
DeleteMessageBatchRequest deleteMessageBatchRequest =
new DeleteMessageBatchRequest();
deleteMessageBatchRequest.setQueueName(queueName);
for (ReceiveMessageResponse response : receiveMessageResponse) {
deleteMessageBatchRequest.addToDeleteMessageBatchRequestEntryList(
new DeleteMessageBatchRequestEntry(response.getReceiptHandle()));
}
messageClient.deleteMessageBatch(deleteMessageBatchRequest);
}
}
Delete Queue:
DeleteQueueRequest deleteQueueRequest = new DeleteQueueRequest(queueName);
queueClient.deleteQueue(deleteQueueRequest);
For more detailed examples please refer to the examples under each language SDK