List of usage examples for com.amazonaws.services.sqs.model SetQueueAttributesRequest SetQueueAttributesRequest
public SetQueueAttributesRequest()
From source file:aws.example.sqs.DeadLetterQueues.java
License:Open Source License
public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: DeadLetterQueues <src_queue_name> <dl_queue_name>"); System.exit(1);//from w ww . j a v a 2s .c o m } String src_queue_name = args[0]; String dl_queue_name = args[1]; final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); // Create source queue try { sqs.createQueue(src_queue_name); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } // Create dead-letter queue try { sqs.createQueue(dl_queue_name); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } // Get dead-letter queue ARN String dl_queue_url = sqs.getQueueUrl(dl_queue_name).getQueueUrl(); GetQueueAttributesResult queue_attrs = sqs .getQueueAttributes(new GetQueueAttributesRequest(dl_queue_url).withAttributeNames("QueueArn")); String dl_queue_arn = queue_attrs.getAttributes().get("QueueArn"); // Set dead letter queue with redrive policy on source queue. String src_queue_url = sqs.getQueueUrl(src_queue_name).getQueueUrl(); SetQueueAttributesRequest request = new SetQueueAttributesRequest().withQueueUrl(src_queue_url) .addAttributesEntry("RedrivePolicy", "{\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"" + dl_queue_arn + "\"}"); sqs.setQueueAttributes(request); }
From source file:aws.example.sqs.LongPolling.java
License:Open Source License
public static void main(String[] args) { final String USAGE = "To run this example, supply the name of a queue to create and\n" + "queue url of an existing queue.\n\n" + "Ex: LongPolling <unique-queue-name> <existing-queue-url>\n"; if (args.length != 2) { System.out.println(USAGE); System.exit(1);/*from w w w. j a va2 s.c om*/ } String queue_name = args[0]; String queue_url = args[1]; final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); // Enable long polling when creating a queue CreateQueueRequest create_request = new CreateQueueRequest().withQueueName(queue_name) .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20"); try { sqs.createQueue(create_request); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } // Enable long polling on an existing queue SetQueueAttributesRequest set_attrs_request = new SetQueueAttributesRequest().withQueueUrl(queue_url) .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20"); sqs.setQueueAttributes(set_attrs_request); // Enable long polling on a message receipt ReceiveMessageRequest receive_request = new ReceiveMessageRequest().withQueueUrl(queue_url) .withWaitTimeSeconds(20); sqs.receiveMessage(receive_request); }
From source file:awslabs.lab31.SolutionCode.java
License:Open Source License
@Override public void grantNotificationPermission(AmazonSQSClient sqsClient, String queueArn, String queueUrl, String topicArn) {// www . j a va2 s .c o m Statement statement = new Statement(Effect.Allow).withActions(SQSActions.SendMessage) .withPrincipals(new Principal("*")).withConditions(ConditionFactory.newSourceArnCondition(topicArn)) .withResources(new Resource(queueArn)); Policy policy = new Policy("SubscriptionPermission").withStatements(statement); HashMap<String, String> attributes = new HashMap<String, String>(); attributes.put("Policy", policy.toJson()); // Create the request to set the queue attributes for policy SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest().withQueueUrl(queueUrl) .withAttributes(attributes); // Set the queue policy sqsClient.setQueueAttributes(setQueueAttributesRequest); }
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 ww w .j a 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; }
From source file:com.eucalyptus.portal.SimpleQueueClientManager.java
License:Open Source License
public void setQueueAttributes(final String queueName, final Map<String, String> queueAttributes) throws Exception { try {/* ww w . j a v a2s .c o m*/ final SetQueueAttributesRequest req = new SetQueueAttributesRequest(); req.setAttributes(queueAttributes); req.setQueueUrl(getQueueUrl(queueName)); getSimpleQueueClient().setQueueAttributes(req); } catch (final AmazonServiceException ex) { throw new Exception("Failed to set queue attributes due to service error", ex); } catch (final AmazonClientException ex) { throw new Exception("Failed to set queue attributes due to client error", ex); } }
From source file:org.apache.camel.component.aws.sqs.SqsEndpoint.java
License:Apache License
private void updateQueueAttributes(AmazonSQS client) { SetQueueAttributesRequest request = new SetQueueAttributesRequest(); request.setQueueUrl(queueUrl);//from w w w .ja v a 2s . co m if (getConfiguration().getDefaultVisibilityTimeout() != null) { request.getAttributes().put(QueueAttributeName.VisibilityTimeout.name(), String.valueOf(getConfiguration().getDefaultVisibilityTimeout())); } if (getConfiguration().getMaximumMessageSize() != null) { request.getAttributes().put(QueueAttributeName.MaximumMessageSize.name(), String.valueOf(getConfiguration().getMaximumMessageSize())); } if (getConfiguration().getMessageRetentionPeriod() != null) { request.getAttributes().put(QueueAttributeName.MessageRetentionPeriod.name(), String.valueOf(getConfiguration().getMessageRetentionPeriod())); } if (getConfiguration().getPolicy() != null) { request.getAttributes().put(QueueAttributeName.Policy.name(), String.valueOf(getConfiguration().getPolicy())); } if (getConfiguration().getReceiveMessageWaitTimeSeconds() != null) { request.getAttributes().put(QueueAttributeName.ReceiveMessageWaitTimeSeconds.name(), String.valueOf(getConfiguration().getReceiveMessageWaitTimeSeconds())); } if (!request.getAttributes().isEmpty()) { LOG.trace("Updating queue '{}' with the provided queue attributes...", configuration.getQueueName()); client.setQueueAttributes(request); LOG.trace("Queue '{}' updated and available at {}'", configuration.getQueueName(), queueUrl); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
/** * //from w w w. ja v a 2s .c o m * @param applicationId */ public void createSQSQueue(String orgAppName) { log.info("Creating Queue for App : " + orgAppName); CreateQueueRequest createQueueRequest = new CreateQueueRequest(); createQueueRequest.setQueueName(AWSUtil.formQueueName(orgAppName)); try { sqsClient.createQueue(createQueueRequest); //Need to do this to get QueueArn to apply right policy on that GetQueueAttributesRequest attributesRequest = new GetQueueAttributesRequest() .withQueueUrl(AWSUtil.formFullQueueUrl(orgAppName)).withAttributeNames("QueueArn"); GetQueueAttributesResult attributesResult = sqsClient.getQueueAttributes(attributesRequest); String queueArn = attributesResult.getAttributes().get("QueueArn"); SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest(); Map<String, String> queueAttributes = new HashMap<String, String>(); //Increasing the max size of SQS messages. queueAttributes.put("MaximumMessageSize", "65536"); //Apply IP address white list String sqsPolicy = AWSUtil.getSQSIPAddressWhiteListPolicy(queueArn); log.info("For queue " + queueArn + " with policy json " + sqsPolicy); queueAttributes.put("Policy", sqsPolicy); setQueueAttributesRequest.setAttributes(queueAttributes); setQueueAttributesRequest.setQueueUrl(AWSUtil.formFullQueueUrl(orgAppName)); sqsClient.setQueueAttributes(setQueueAttributesRequest); } catch (AmazonServiceException ase) { log.error("Problem creating queue in sqs"); log.error(ase); } catch (AmazonClientException ace) { log.error(ace); } }