List of usage examples for com.amazonaws.services.sqs AmazonSQSClient getQueueAttributes
@Override
public GetQueueAttributesResult getQueueAttributes(GetQueueAttributesRequest request)
Gets attributes for the specified queue.
From source file:SimpleQueueService.java
License:Open Source License
public static int getNumberOFTasksRunning() { // returns the number of amazon tasks running AmazonSQSClient sqs = new AmazonSQSClient(new ClasspathPropertiesFileCredentialsProvider()); CreateQueueRequest createQueueRequest = new CreateQueueRequest("taskQueue"); String myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); GetQueueAttributesRequest request = new GetQueueAttributesRequest(); request = request.withAttributeNames("ApproximateNumberOfMessages"); request = request.withQueueUrl(myQueueUrl); Map<String, String> attrs = sqs.getQueueAttributes(request).getAttributes(); // get the approximate number of messages in the queue int sizeOfMessages = Integer.parseInt(attrs.get("ApproximateNumberOfMessages")); System.out.println("sizeOfMessages " + sizeOfMessages); return sizeOfMessages; }
From source file:awslabs.lab31.SolutionCode.java
License:Open Source License
@Override public String getQueueArn(AmazonSQSClient sqsClient, String queueUrl) { // TODO: Construct a GetQueueAttributesRequest for the specified queue and for the attribute named "QueueArn". GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest().withQueueUrl(queueUrl) .withAttributeNames("QueueArn"); // TODO: Submit the request using the getQueueAttributes method of the sqsClient object. GetQueueAttributesResult getQueueAttributesResult = sqsClient.getQueueAttributes(getQueueAttributesRequest); // TODO: Return the QueueArn attribute value. return getQueueAttributesResult.getAttributes().get("QueueArn"); }
From source file:awslabs.lab31.StudentCode.java
License:Open Source License
/** * Query the SQS service for the ARN of the specified queue and return it. Hint: Use the getQueueAttributes() method * of the client object. The attribute to request is named QueueArn. * /*from ww w.jav a 2 s .c o m*/ * @param sqsClient The SQS Client object. * @param queueUrl The URL for the queue to inspect. * @return A string containing the ARN for the queue. */ @Override public String getQueueArn(AmazonSQSClient sqsClient, String queueUrl) { GetQueueAttributesRequest request = new GetQueueAttributesRequest().withAttributeNames("QueueArn") .withQueueUrl(queueUrl); GetQueueAttributesResult result = sqsClient.getQueueAttributes(request); return result.getAttributes().get("QueueArn"); }
From source file:com.connexience.server.model.archive.glacier.SetupUtils.java
License:Open Source License
public static SQSInfo setupSQS(String accessKey, String secretKey, String domainName, String vaultName) { SQSInfo sqsInfo = null;//from w ww .ja v a 2 s .c om try { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonSQSClient amazonSQSClient = new AmazonSQSClient(awsCredentials); amazonSQSClient.setEndpoint("https://sqs." + domainName + ".amazonaws.com/"); String queueName = vaultName + "-inkspot_glacier-queue"; CreateQueueRequest createQueueRequest = new CreateQueueRequest(); createQueueRequest.withQueueName(queueName); CreateQueueResult createQueueResult = amazonSQSClient.createQueue(createQueueRequest); if (createQueueResult != null) { String queueURL = createQueueResult.getQueueUrl(); GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest(); getQueueAttributesRequest.withQueueUrl(queueURL); getQueueAttributesRequest.withAttributeNames("QueueArn"); GetQueueAttributesResult getQueueAttributesResult = amazonSQSClient .getQueueAttributes(getQueueAttributesRequest); if (getQueueAttributesResult != null) { String queueARN = getQueueAttributesResult.getAttributes().get("QueueArn"); Statement sqsStatement = new Statement(Effect.Allow); sqsStatement.withPrincipals(Principal.AllUsers); sqsStatement.withActions(SQSActions.SendMessage); sqsStatement.withResources(new Resource(queueARN)); Policy sqsPolicy = new Policy(); sqsPolicy.withStatements(sqsStatement); Map<String, String> sqsAttributes = new HashMap<>(); sqsAttributes.put("Policy", sqsPolicy.toJson()); SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest(); setQueueAttributesRequest.withQueueUrl(queueURL); setQueueAttributesRequest.withAttributes(sqsAttributes); amazonSQSClient.setQueueAttributes(setQueueAttributesRequest); sqsInfo = new SQSInfo(queueARN, queueURL); } else logger.warn("Unable to get queue attributes: \"" + queueName + "\""); } else logger.warn("Unable to create queue: \"" + queueName + "\""); amazonSQSClient.shutdown(); } catch (AmazonServiceException amazonServiceException) { logger.warn("AmazonServiceException: " + amazonServiceException); logger.debug(amazonServiceException); } catch (IllegalArgumentException illegalArgumentException) { logger.warn("IllegalArgumentException: " + illegalArgumentException); logger.debug(illegalArgumentException); } catch (AmazonClientException amazonClientException) { logger.warn("AmazonClientException: " + amazonClientException); logger.debug(amazonClientException); } catch (Throwable throwable) { logger.warn("Throwable: " + throwable); logger.debug(throwable); } return sqsInfo; }