List of usage examples for com.amazonaws.services.sqs.model SetQueueAttributesRequest SetQueueAttributesRequest
public SetQueueAttributesRequest(String queueUrl, java.util.Map<String, String> attributes)
From source file:com.amazon.aws.demo.anonymous.sqs.SimpleQueue.java
License:Open Source License
public static void allowNotifications(String queueUrl, String topicArn) { HashMap<String, String> attributes = new HashMap<String, String>(); attributes.put("Policy", generateSqsPolicyForTopic(getQueueArn(queueUrl), topicArn)); getInstance().setQueueAttributes(new SetQueueAttributesRequest(queueUrl, attributes)); }
From source file:com.clicktravel.infrastructure.messaging.aws.sqs.SqsQueueResource.java
License:Apache License
/** * Sets the {@link Policy} of the AWS SQS queue * @param policy {@link Policy} to set//ww w . j av a2 s . com */ public void setPolicy(final Policy policy) throws AmazonClientException { final Map<String, String> queueAttributes = Collections.singletonMap(AWS_POLICY_ATTRIBUTE, policy.toJson()); amazonSqsClient.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, queueAttributes)); }
From source file:com.comcast.cqs.controller.CQSEditQueueAttributePage.java
License:Apache License
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (redirectUnauthenticatedUser(request, response)) { return;//from ww w. j a va 2 s . co m } CMBControllerServlet.valueAccumulator.initializeAllCounters(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String userId = request.getParameter("userId"); Map<?, ?> params = request.getParameterMap(); String queueName = request.getParameter("queueName"); String queueUrl = Util.getAbsoluteQueueUrlForName(queueName, userId); connect(request); out.println("<html>"); simpleHeader(request, out, "View/Edit Queue Attributes"); if (params.containsKey("Update")) { String visibilityTimeout = request.getParameter("visibilityTimeout"); String maximumMessageSize = request.getParameter("maximumMessageSize"); String messageRetentionPeriod = request.getParameter("messageRetentionPeriod"); String delaySeconds = request.getParameter("delaySeconds"); String receiveMessageWaitTimeSeconds = request.getParameter("receiveMessageWaitTimeSeconds"); String numberOfPartitions = request.getParameter("numberOfPartitions"); String numberOfShards = request.getParameter("numberOfShards"); String isCompressed = request.getParameter("isCompressed"); try { Map<String, String> attributes = new HashMap<String, String>(); if (visibilityTimeout != null && !visibilityTimeout.equals("")) { attributes.put("VisibilityTimeout", visibilityTimeout); } if (maximumMessageSize != null && !maximumMessageSize.equals("")) { attributes.put("MaximumMessageSize", maximumMessageSize); } if (messageRetentionPeriod != null && !messageRetentionPeriod.equals("")) { attributes.put("MessageRetentionPeriod", messageRetentionPeriod); } if (delaySeconds != null && !delaySeconds.equals("")) { attributes.put("DelaySeconds", delaySeconds); } if (receiveMessageWaitTimeSeconds != null && !receiveMessageWaitTimeSeconds.equals("")) { attributes.put("ReceiveMessageWaitTimeSeconds", receiveMessageWaitTimeSeconds); } if (numberOfPartitions != null && !numberOfPartitions.equals("")) { attributes.put("NumberOfPartitions", numberOfPartitions); } if (numberOfPartitions != null && !numberOfPartitions.equals("")) { attributes.put("NumberOfShards", numberOfShards); } if (isCompressed != null && !isCompressed.equals("")) { attributes.put("IsCompressed", isCompressed); } SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest(queueUrl, attributes); sqs.setQueueAttributes(setQueueAttributesRequest); logger.debug("event=set_queue_attributes queue_ulr=" + queueUrl + " user_id= " + userId); } catch (Exception ex) { logger.error("event=set_queue_attributes queue_ulr=" + queueUrl + " user_id= " + userId, ex); throw new ServletException(ex); } out.println("<body onload='javascript:window.opener.location.reload();window.close();'>"); } else { String visibilityTimeout = ""; String maximumMessageSize = ""; String messageRetentionPeriod = ""; String delaySeconds = ""; String receiveMessageWaitTimeSeconds = ""; String numberOfPartitions = ""; String numberOfShards = ""; String isCompressed = ""; if (queueUrl != null) { Map<String, String> attributes = null; try { GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest(queueUrl); getQueueAttributesRequest .setAttributeNames(Arrays.asList("VisibilityTimeout", "MaximumMessageSize", "MessageRetentionPeriod", "DelaySeconds", "ReceiveMessageWaitTimeSeconds", "NumberOfPartitions", "NumberOfShards", "IsCompressed")); GetQueueAttributesResult getQueueAttributesResult = sqs .getQueueAttributes(getQueueAttributesRequest); attributes = getQueueAttributesResult.getAttributes(); visibilityTimeout = attributes.get("VisibilityTimeout"); maximumMessageSize = attributes.get("MaximumMessageSize"); messageRetentionPeriod = attributes.get("MessageRetentionPeriod"); delaySeconds = attributes.get("DelaySeconds"); receiveMessageWaitTimeSeconds = attributes.get("ReceiveMessageWaitTimeSeconds"); numberOfPartitions = attributes.get("NumberOfPartitions"); numberOfShards = attributes.get("NumberOfShards"); isCompressed = attributes.get("IsCompressed"); } catch (Exception ex) { logger.error("event=failed_to_get_attributes queue_url=" + queueUrl, ex); throw new ServletException(ex); } } out.println("<body>"); out.println("<h1>View/Edit Queue Attributes</h1>"); out.println("<h3>" + queueUrl + "</h3>"); out.println( "<form action=\"/webui/cqsuser/editqueueattributes?queueName=" + queueName + "\" method=POST>"); out.println("<input type='hidden' name='userId' value='" + userId + "'>"); out.println("<table>"); out.println("<tr><td colspan=2><b><font color='orange'>Queue Attributes</font></b></td></tr>"); out.println("<tr><td colspan=2><b>Apply these attributes to the queue:</b></td></tr>"); out.println( "<tr><td>Visibility Timeout:</td><td><input type='text' name='visibilityTimeout' size='50' value='" + visibilityTimeout + "'></td></tr>"); out.println("<tr><td> </td><td><I><font color='grey'>Default " + CMBProperties.getInstance().getCQSVisibilityTimeOut() + " sec</font></I></td></tr>"); out.println( "<tr><td>Maximum Message Size:</td><td><input type='text' name='maximumMessageSize' size='50' value='" + maximumMessageSize + "'></td></tr>"); out.println("<tr><td> </td><td><I><font color='grey'>Default " + CMBProperties.getInstance().getCQSMaxMessageSize() + " bytes</font></I></td></tr>"); out.println( "<tr><td>Message Retention Period:</td><td><input type='text' name='messageRetentionPeriod' size='50' value='" + messageRetentionPeriod + "'></td></tr>"); out.println("<tr><td> </td><td><I><font color='grey'>Default " + CMBProperties.getInstance().getCQSMessageRetentionPeriod() + " sec</font></I></td></tr>"); out.println("<tr><td>Delay Seconds:</td><td><input type='text' name='delaySeconds' size='50' value='" + delaySeconds + "'></td></tr>"); out.println("<tr><td> </td><td><I><font color='grey'>Default " + CMBProperties.getInstance().getCQSMessageDelaySeconds() + " sec</font></I></td></tr>"); out.println( "<tr><td>Receive Message Wait Time Seconds:</td><td><input type='text' name='receiveMessageWaitTimeSeconds' size='50' value='" + receiveMessageWaitTimeSeconds + "'></td></tr>"); out.println( "<tr><td> </td><td><I><font color='grey'>Default 0 sec, max 20 sec</font></I></td></tr>"); out.println( "<tr><td>Number Of Partitions:</td><td><input type='text' name='numberOfPartitions' size='50' value='" + numberOfPartitions + "'></td></tr>"); out.println( "<tr><td> </td><td><I><font color='grey'>Default 100, minimum 1 partition(s)</font></I></td></tr>"); out.println( "<tr><td>Number Of Shards:</td><td><input type='text' name='numberOfShards' size='50' value='" + numberOfShards + "'></td></tr>"); out.println( "<tr><td> </td><td><I><font color='grey'>Default 1, maximum 100 shards</font></I></td></tr>"); out.println("<tr><td>Compressed:</td><td><input type='text' name='isCompressed' size='50' value='" + isCompressed + "'></td></tr>"); out.println( "<tr><td> </td><td><I><font color='grey'>Valid values: true or false</font></I></td></tr>"); out.println("<tr><td> </td><td> </td></tr>"); out.println("<tr><td colspan=2><hr/></td></tr>"); out.println( "<tr><td colspan=2 align=right><input type='button' onclick='window.close()' value='Cancel'><input type='submit' name='Update' value='Update'></td></tr></table></form>"); } out.println("</body></html>"); CMBControllerServlet.valueAccumulator.deleteAllCounters(); }
From source file:com.leverno.ysbos.archive.example.AmazonGlacierDownloadInventoryWithSQSPolling.java
License:Open Source License
private static void setupSQS() { CreateQueueRequest request = new CreateQueueRequest().withQueueName(sqsQueueName); CreateQueueResult result = sqsClient.createQueue(request); sqsQueueURL = result.getQueueUrl();/*from w w w.j a v a 2 s. c o m*/ GetQueueAttributesRequest qRequest = new GetQueueAttributesRequest().withQueueUrl(sqsQueueURL) .withAttributeNames("QueueArn"); GetQueueAttributesResult qResult = sqsClient.getQueueAttributes(qRequest); sqsQueueARN = qResult.getAttributes().get("QueueArn"); Policy sqsPolicy = new Policy() .withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers) .withActions(SQSActions.SendMessage).withResources(new Resource(sqsQueueARN))); Map<String, String> queueAttributes = new HashMap<String, String>(); queueAttributes.put("Policy", sqsPolicy.toJson()); sqsClient.setQueueAttributes(new SetQueueAttributesRequest(sqsQueueURL, queueAttributes)); }
From source file:com.pocketdealhunter.HotDealsMessagesUtil.java
License:Open Source License
private void addPolicyToQueueForTopic(String queueUrl, String queueArn) { HashMap<String, String> attributes = new HashMap<String, String>(); attributes.put("Policy", generateSqsPolicyForTopic(queueArn, this.topicARN)); this.sqsClient.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, attributes)); // It can take some time for policy to propagate to the queue. }
From source file:io.konig.maven.CreateAwsSqsQueueAction.java
License:Apache License
public AwsDeployment from(String path) throws Exception { String cfTemplatePresent = System.getProperty("cfTemplatePresent"); if (cfTemplatePresent == null || cfTemplatePresent.equals("N")) { try {/*from www . j av a 2 s.com*/ File file = deployment.file(path); ObjectMapper mapper = new ObjectMapper(); S3Bucket bucket = mapper.readValue(file, S3Bucket.class); deployment.verifyAWSCredentials(); QueueConfiguration queueConfig = bucket.getNotificationConfiguration().getQueueConfiguration(); if (queueConfig != null && queueConfig.getQueue() != null) { String accountId = ""; if (System.getProperty("aws-account-id") != null) { accountId = System.getProperty("aws-account-id"); } Queue queue = queueConfig.getQueue(); Regions regions = Regions.fromName(queue.getRegion()); AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(deployment.getCredential()) .withRegion(regions).build(); AmazonSNS sns = AmazonSNSClientBuilder.standard().withCredentials(deployment.getCredential()) .withRegion(regions).build(); CreateQueueResult result = sqs.createQueue(queue.getResourceName()); String topicArn = StringUtils.replaceOnce( bucket.getNotificationConfiguration().getTopicConfiguration().getTopicArn(), "${aws-account-id}", accountId); String queueArn = StringUtils.replaceOnce( bucket.getNotificationConfiguration().getQueueConfiguration().getQueueArn(), "${aws-account-id}", accountId); deployment.setResponse("Queue " + queueArn + " is created"); Policy policy = new Policy() .withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers) .withActions(SQSActions.SendMessage).withResources(new Resource(queueArn)) .withConditions(ConditionFactory.newSourceArnCondition(topicArn))); Map<String, String> queueAttributes = new HashMap<String, String>(); queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson()); deployment.setResponse("Queue Policy Configured : " + policy.toJson()); sqs.setQueueAttributes(new SetQueueAttributesRequest(result.getQueueUrl(), queueAttributes)); Topics.subscribeQueue(sns, sqs, topicArn, result.getQueueUrl()); deployment.setResponse( "Subscription is created : Topic [" + topicArn + "], Queue [" + queueArn + "]"); } else { deployment.setResponse("Queue Configuration Failed"); } } catch (Exception e) { throw e; } } else { deployment.setResponse("Queue will be created through cloud formation template"); } return deployment; }
From source file:org.duracloud.common.sns.SnsSubscriptionManager.java
License:Apache License
public synchronized void connect() { if (initialized) { throw new DuraCloudRuntimeException("this manager is already connected"); }/*w w w . j av a 2 s . c o m*/ //create sqs queue log.info("creating sqs queue"); CreateQueueRequest request = new CreateQueueRequest(this.queueName); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("ReceiveMessageWaitTimeSeconds", "20"); request.setAttributes(attributes); CreateQueueResult result; try { result = sqsClient.createQueue(request); this.queueUrl = result.getQueueUrl(); log.info("sqs queue created: {}", this.queueUrl); } catch (QueueNameExistsException ex) { log.info("queue with name {} already exists."); GetQueueUrlResult queueUrlResult = sqsClient.getQueueUrl(this.queueName); this.queueUrl = queueUrlResult.getQueueUrl(); log.info("sqs queue url retrieved: {}", this.queueUrl); } String queueArnKey = "QueueArn"; GetQueueAttributesResult getQueueAttrResult = sqsClient.getQueueAttributes(this.queueUrl, Arrays.asList(queueArnKey)); log.info("subscribing {} to {}", queueUrl, topicArn); String queueArn = getQueueAttrResult.getAttributes().get(queueArnKey); SubscribeResult subscribeResult = this.snsClient.subscribe(topicArn, "sqs", queueArn); this.subscriptionArn = subscribeResult.getSubscriptionArn(); Map<String, String> queueAttributes = new HashMap<String, String>(); queueAttributes.put("Policy", generateSqsPolicyForTopic(queueArn, topicArn)); sqsClient.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, queueAttributes)); log.info("subscription complete: {}", this.subscriptionArn); //subscribe queue to topic this.initialized = true; startPolling(); }
From source file:org.mule.modules.sqs.SQSConnector.java
License:Open Source License
/** * Sets a queue attribute. This is provided to expose the underlying functionality, although * the only attribute at this time is visibility timeout. * <p/>/*from ww w . j av a 2s . c o m*/ * {@sample.xml ../../../doc/mule-module-sqs.xml.sample sqs:set-queue-attribute} * * @param attribute name of the attribute being set * @param value the value being set for this attribute * @throws AmazonClientException * If any internal errors are encountered inside the client while * attempting to make the request or handle the response. For example * if a network connection is not available. * @throws AmazonServiceException * If an error response is returned by AmazonSQS indicating * either a problem with the data in the request, or a server side issue. */ @Processor @InvalidateConnectionOn(exception = AmazonClientException.class) public void setQueueAttribute(String attribute, String value) throws AmazonServiceException { Map<String, String> attributes = new HashMap<String, String>(); attributes.put(attribute, value); msgQueue.setQueueAttributes(new SetQueueAttributesRequest(getQueueUrl(), attributes)); }
From source file:org.transitime.maintenance.AwsGlacierInventoryRetriever.java
License:Open Source License
/** * For retrieving vault inventory. For initializing SQS for determining when * job completed. Does nothing if member snsTopicName is null. Sets members * sqsQueueURL, sqsQueueARN, and sqsClient. *//*from w w w . j av a2s .co m*/ private void setupSQS() { // If no sqsQueueName setup then simply return if (sqsQueueName == null) return; CreateQueueRequest request = new CreateQueueRequest().withQueueName(sqsQueueName); CreateQueueResult result = sqsClient.createQueue(request); sqsQueueURL = result.getQueueUrl(); GetQueueAttributesRequest qRequest = new GetQueueAttributesRequest().withQueueUrl(sqsQueueURL) .withAttributeNames("QueueArn"); GetQueueAttributesResult qResult = sqsClient.getQueueAttributes(qRequest); sqsQueueARN = qResult.getAttributes().get("QueueArn"); Policy sqsPolicy = new Policy() .withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers) .withActions(SQSActions.SendMessage).withResources(new Resource(sqsQueueARN))); Map<String, String> queueAttributes = new HashMap<String, String>(); queueAttributes.put("Policy", sqsPolicy.toJson()); sqsClient.setQueueAttributes(new SetQueueAttributesRequest(sqsQueueURL, queueAttributes)); }
From source file:smartthings.brave.sqs.TracingAmazonSQSClient.java
License:Apache License
@Override public SetQueueAttributesResult setQueueAttributes(String queueUrl, Map<String, String> attributes) { return this.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, attributes)); }