use of com.amazonaws.services.sqs.model.Message in project glacier-cli by carlossg.
the class Glacier method waitForJobToComplete.
private Boolean waitForJobToComplete(String jobId, String sqsQueueUrl) throws InterruptedException, JsonParseException, IOException {
Boolean messageFound = false;
Boolean jobSuccessful = false;
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = mapper.getJsonFactory();
Date start = new Date();
while (!messageFound) {
long minutes = (new Date().getTime() - start.getTime()) / 1000 / 60;
System.out.println("Checking for messages: " + minutes + " elapsed");
List<Message> msgs = sqsClient.receiveMessage(new ReceiveMessageRequest(sqsQueueUrl).withMaxNumberOfMessages(10)).getMessages();
if (msgs.size() > 0) {
for (Message m : msgs) {
JsonParser jpMessage = factory.createJsonParser(m.getBody());
JsonNode jobMessageNode = mapper.readTree(jpMessage);
String jobMessage = jobMessageNode.get("Message").getTextValue();
JsonParser jpDesc = factory.createJsonParser(jobMessage);
JsonNode jobDescNode = mapper.readTree(jpDesc);
String retrievedJobId = jobDescNode.get("JobId").getTextValue();
String statusCode = jobDescNode.get("StatusCode").getTextValue();
if (retrievedJobId.equals(jobId)) {
messageFound = true;
if (statusCode.equals("Succeeded")) {
jobSuccessful = true;
}
}
}
} else {
Thread.sleep(sleepTime * 1000);
}
}
return (messageFound && jobSuccessful);
}
use of com.amazonaws.services.sqs.model.Message in project camel by apache.
the class SqsFilterMessagesWithNoDeleteTest method populateMessages.
// put some test messages onto the 'queue'
private void populateMessages(AmazonSQSClientMock clientMock) {
Message message = new Message();
message.setBody("Message: hello, world!");
message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5");
clientMock.messages.add(message);
}
use of com.amazonaws.services.sqs.model.Message in project camel by apache.
the class AmazonSQSClientMock method receiveMessage.
@Override
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) throws AmazonServiceException, AmazonClientException {
Integer maxNumberOfMessages = receiveMessageRequest.getMaxNumberOfMessages() != null ? receiveMessageRequest.getMaxNumberOfMessages() : Integer.MAX_VALUE;
ReceiveMessageResult result = new ReceiveMessageResult();
Collection<Message> resultMessages = new ArrayList<Message>();
synchronized (messages) {
int fetchSize = 0;
for (Iterator<Message> iterator = messages.iterator(); iterator.hasNext() && fetchSize < maxNumberOfMessages; fetchSize++) {
Message rc = iterator.next();
resultMessages.add(rc);
iterator.remove();
scheduleCancelInflight(receiveMessageRequest.getQueueUrl(), rc);
}
}
result.setMessages(resultMessages);
return result;
}
use of com.amazonaws.services.sqs.model.Message in project camel by apache.
the class SqsConcurrentConsumerTest method createDummyMessages.
private void createDummyMessages(AmazonSQSClientMock client, int numMessages) {
for (int counter = 0; counter < numMessages; counter++) {
Message message = new Message();
message.setBody("Message " + counter);
message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5");
client.messages.add(message);
}
}
use of com.amazonaws.services.sqs.model.Message in project aws-doc-sdk-examples by awsdocs.
the class SendReceiveMessages method main.
public static void main(String[] args) {
final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
try {
CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
} catch (AmazonSQSException e) {
if (!e.getErrorCode().equals("QueueAlreadyExists")) {
throw e;
}
}
String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
SendMessageRequest send_msg_request = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hello world").withDelaySeconds(5);
sqs.sendMessage(send_msg_request);
// Send multiple messages to the queue
SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest().withQueueUrl(queueUrl).withEntries(new SendMessageBatchRequestEntry("msg_1", "Hello from message 1"), new SendMessageBatchRequestEntry("msg_2", "Hello from message 2").withDelaySeconds(10));
sqs.sendMessageBatch(send_batch_request);
// receive messages from the queue
List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();
// delete messages from the queue
for (Message m : messages) {
sqs.deleteMessage(queueUrl, m.getReceiptHandle());
}
}
Aggregations