List of usage examples for com.amazonaws.services.sqs.model Message getMD5OfBody
public String getMD5OfBody()
An MD5 digest of the non-URL-encoded message body string.
From source file:com.comcast.cqs.model.CQSMessage.java
License:Apache License
public CQSMessage(Message message) { this.messageId = message.getMessageId(); this.receiptHandle = message.getReceiptHandle(); this.body = message.getBody(); this.mD5OfBody = message.getMD5OfBody(); }
From source file:com.dxc.temp.SimpleQueueServiceSample.java
License:Open Source License
public static void main(String[] args) throws Exception { BasicConfigurator.configure();// w ww . jav a2 s.com /* * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } System.out.println(String.format("Found AWSAccessKeyId: %s", credentials.getAWSAccessKeyId())); System.out.println(String.format("Found AWSAccessSecretKey: %s", credentials.getAWSSecretKey())); AmazonSQS sqs = new AmazonSQSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usEast1); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "Message body text")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message // System.out.println("Deleting a message.\n"); // String messageReceiptHandle = messages.get(0).getReceiptHandle(); // sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); // Delete a queue // You must wait 60 seconds after deleting a queue before you can create another with the same name // System.out.println("Deleting the test queue.\n"); // sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.easarrive.aws.plugins.common.service.impl.SQSNotificationService.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j av a 2 s . com */ @Override public boolean isSignatureMessageValid(Message message) { if (message == null) { return false; } String md5MessageBody = message.getMD5OfBody(); if (StringUtil.isEmpty(md5MessageBody)) { return false; } String messageBody = message.getBody(); try { return md5MessageBody.equals(DigestUtils.md5Hex(messageBody)); } catch (Exception e) { return false; } }
From source file:com.espressologic.aws.sqs.SqsAmazonService.java
License:Open Source License
private static void displayMessageContent(Message message) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); }/*from ww w .j a v a2s. c o m*/ }
From source file:com.ibm.connectors.AmazonSQS.AmazonSQSInputConnector.java
License:Open Source License
@Override public void poll(long waitInterval) { Properties properties = new Properties(); String access_key_id = getProperty("AccessKeyId"); String secret_access_key = getProperty("SecretAccessKey"); BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key); AmazonSQS sqs = new AmazonSQSClient(credentials); // Region selection Region region = Region.getRegion(Regions.fromName(getProperty("region"))); sqs.setRegion(region);//from w w w . j av a2 s . com GetQueueUrlResult queueUrl = sqs.getQueueUrl(getProperty("Queue")); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl.getQueueUrl()); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); String outputMessage = ""; // if there are messages then do the processing if (messages.size() > 0) { //append the message properties to the localenv tree for (Message message : messages) { properties.setProperty("MessageId", message.getMessageId()); properties.setProperty("ReceiptHandle", message.getReceiptHandle()); properties.setProperty("MD5OfBody", message.getMD5OfBody()); // get the message body to a string outputMessage = message.getBody(); } properties.setProperty("queueUrl", queueUrl.getQueueUrl()); // delete the message from the queue String messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(queueUrl.getQueueUrl(), messageReceiptHandle)); ConnectorCallback callback = getCallback(); callback.processInboundData(outputMessage.getBytes(), properties); } }
From source file:com.mateusz.mateuszsqs.SQSConfig.java
public static List<String> getMessages(AmazonSQS sqs, String sqsURL) { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(sqsURL); List<Message> messages = sqs.receiveMessage(receiveMessageRequest.withMessageAttributeNames("All")) .getMessages();//w ww .j a v a2 s . co m List<String> filesToProcess = new ArrayList<String>(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Map.Entry<String, MessageAttributeValue> entry : message.getMessageAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue().getStringValue()); filesToProcess.add(entry.getValue().getStringValue()); } System.out.println("Deleting a message.\n"); String messageReceiptHandle = message.getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(sqsURL, messageReceiptHandle)); } return filesToProcess; }
From source file:com.rodosaenz.samples.aws.sqs.AwsSqsSimpleExample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//w w w . ja va2 s .c o m * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException("Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials); Region usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); String queue_name = "com-rodosaenz-examples-aws-sqs"; try { // Create a queue System.out.println("Creating a new SQS queue called " + queue_name + ".\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queue_name); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message System.out.println("Sending a message to " + queue_name + ".\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); receiveMessageRequest.setMaxNumberOfMessages(1); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); //Get attributes GetQueueAttributesRequest request = new GetQueueAttributesRequest(myQueueUrl).withAttributeNames("All"); final Map<String, String> attributes = sqs.getQueueAttributes(request).getAttributes(); System.out.println(" Policy: " + attributes.get("Policy")); System.out.println(" MessageRetentionPeriod: " + attributes.get("MessageRetentionPeriod")); System.out.println(" MaximumMessageSize: " + attributes.get("MaximumMessageSize")); System.out.println(" CreatedTimestamp: " + attributes.get("CreatedTimestamp")); System.out.println(" VisibilityTimeout: " + attributes.get("VisibilityTimeout")); System.out.println(" QueueArn: " + attributes.get("QueueArn")); System.out.println(" ApproximateNumberOfMessages: " + attributes.get("ApproximateNumberOfMessages")); System.out.println(" ApproximateNumberOfMessagesNotVisible: " + attributes.get("ApproximateNumberOfMessagesNotVisible")); System.out.println(" DelaySeconds: " + attributes.get("DelaySeconds")); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.sjsu.cmpe281.team06.NovaMiaas.SimpleQueueServiceSample.java
License:Open Source License
public static void main(String[] args) throws Exception { /*//from w w w. j a v a 2 s.c om * This credentials provider implementation loads your AWS credentials * from a properties file at the root of your classpath. * * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this * sample. * http://aws.amazon.com/security-credentials */ AmazonSQS sqs = new AmazonSQSClient(new ClasspathPropertiesFileCredentialsProvider()); Region usWest1 = Region.getRegion(Regions.US_WEST_1); sqs.setRegion(usWest1); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("MyQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my new message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageRecieptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl)); } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.springboot.jms.AWSJmsSendAndReceive.java
License:Open Source License
public static void testAWSQueue() throws Exception { /*/* w ww .ja v a 2 s. c om*/ * The ProfileCredentialsProvider will return your [default] * credential profile by reading from the credentials file located at * (~/.aws/credentials). */ /* AWSCredentials credentials = null; try { credentials = new ProfileCredentialsProvider().getCredentials(); } catch (Exception e) { throw new AmazonClientException( "Cannot load the credentials from the credential profiles file. " + "Please make sure that your credentials file is at the correct " + "location (~/.aws/credentials), and is in valid format.", e); } AmazonSQS sqs = new AmazonSQSClient(credentials);*/ AmazonSQS sqs = new AmazonSQSClient(new BasicAWSCredentials("", "")); Region usWest2 = Region.getRegion(Regions.US_EAST_1); sqs.setRegion(usWest2); System.out.println("==========================================="); System.out.println("Getting Started with Amazon SQS"); System.out.println("===========================================\n"); try { /* // Create a queue System.out.println("Creating a new SQS queue called MyQueue.\n"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("PetQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl();*/ String myQueueUrl = "https://sqs.us-east-1.amazonaws.com/918558451804/PetQueue"; // List queues System.out.println("Listing all queues in your account.\n"); for (String queueUrl : sqs.listQueues().getQueueUrls()) { System.out.println(" QueueUrl: " + queueUrl); } System.out.println(); // Send a message System.out.println("Sending a message to MyQueue.\n"); sqs.sendMessage(new SendMessageRequest(myQueueUrl, "This is my message text.")); // Receive messages System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); for (Message message : messages) { System.out.println(" Message"); System.out.println(" MessageId: " + message.getMessageId()); System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); System.out.println(" MD5OfBody: " + message.getMD5OfBody()); System.out.println(" Body: " + message.getBody()); for (Entry<String, String> entry : message.getAttributes().entrySet()) { System.out.println(" Attribute"); System.out.println(" Name: " + entry.getKey()); System.out.println(" Value: " + entry.getValue()); } } System.out.println(); // Delete a message System.out.println("Deleting a message.\n"); String messageReceiptHandle = messages.get(0).getReceiptHandle(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageReceiptHandle)); /* // Delete a queue System.out.println("Deleting the test queue.\n"); sqs.deleteQueue(new DeleteQueueRequest(myQueueUrl));*/ } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, which means your request made it " + "to Amazon SQS, but was rejected with an error response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, which means the client encountered " + "a serious internal problem while trying to communicate with SQS, such as not " + "being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); } }
From source file:com.streamsets.pipeline.origin.sqs.SampleSource.java
License:Apache License
/** * {@inheritDoc}// w w w . j a v a 2 s. c o m */ @Override public String produce(String lastSourceOffset, int maxBatchSize, BatchMaker batchMaker) throws StageException { // Offsets can vary depending on the data source. Here we use an integer as an example only. long nextSourceOffset = 0; if (lastSourceOffset != null) { nextSourceOffset = Long.parseLong(lastSourceOffset); } int numRecords = 0; // TODO: As the developer, implement your logic that reads from a data source in this method. // Create records and add to batch. Records must have a string id. This can include the source offset // or other metadata to help uniquely identify the record itself. AWSSQSUtil awssqsUtil = new AWSSQSUtil(getAccessKey(), getSecreteKey(), getQueueName(), getEndPoint()); String queuName = awssqsUtil.getQueueName(); String queueUrl = awssqsUtil.getQueueUrl(queuName); //maximum number of meesage that can be retrieve in one request int maxMessagCount = 10; List<Message> messages = awssqsUtil.getMessagesFromQueue(queueUrl, maxMessagCount); for (Message message : messages) { Record record = getContext().createRecord("messageId::" + message.getMessageId()); Map<String, Field> map = new HashMap<>(); map.put("receipt_handle", Field.create(message.getReceiptHandle())); map.put("md5_of_body", Field.create(message.getMD5OfBody())); map.put("body", Field.create(message.getBody())); JSONObject attributeJson = new JSONObject(); for (Map.Entry<String, String> entry : message.getAttributes().entrySet()) { attributeJson.put(entry.getKey(), entry.getValue()); } map.put("attribute_list", Field.create(attributeJson.toString())); record.set(Field.create(map)); batchMaker.addRecord(record); ++nextSourceOffset; ++numRecords; if (getDeleteFlag()) { awssqsUtil.deleteMessageFromQueue(queueUrl, message); } } return String.valueOf(nextSourceOffset); }