List of usage examples for com.amazonaws.services.sqs.model CreateQueueRequest CreateQueueRequest
public CreateQueueRequest()
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);/* ww w . j a v a2s . c o m*/ } 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 String createQueue(AmazonSQSClient sqsClient, String queueName) { // TODO: Construct a CreateQueueRequest object using the provided queue name. CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); // TODO: Submit the request using the createQueue method of the sqsClient object. CreateQueueResult createQueueResult = sqsClient.createQueue(createQueueRequest); // TODO: Return the queue URL from the request result. return createQueueResult.getQueueUrl(); }
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;/*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.datatorrent.lib.io.jms.SQSTestBase.java
License:Apache License
/** * create a queue we can use for testing * * @throws Exception/* w w w.jav a 2s . co m*/ */ @Before public void beforTest() throws Exception { validateAssumption(); // Create a queue CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(getCurrentQueueName()); currentQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); }
From source file:com.eucalyptus.portal.SimpleQueueClientManager.java
License:Open Source License
public void createQueue(final String queueName, final Map<String, String> queueAttributes) throws Exception { try {//ww w . j av a 2 s . c o m final CreateQueueRequest req = new CreateQueueRequest(); if (queueAttributes != null) req.setAttributes(queueAttributes); req.setQueueName(queueName); if (getSimpleQueueClient().createQueue(req).getQueueUrl() == null) throw new Exception("Null queue URL is returned"); } catch (final AmazonServiceException ex) { throw new Exception("Failed to create queue due to service error", ex); } catch (final AmazonClientException ex) { throw new Exception("Failed to create queue due to client error", ex); } }
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 ww w . ja v a2 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.netflix.conductor.contribs.queue.sqs.SQSObservableQueue.java
License:Apache License
@VisibleForTesting String getOrCreateQueue() {/*from www . ja v a 2 s . c om*/ List<String> queueUrls = listQueues(queueName); if (queueUrls == null || queueUrls.isEmpty()) { CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); CreateQueueResult result = client.createQueue(createQueueRequest); return result.getQueueUrl(); } else { return queueUrls.get(0); } }
From source file:com.netflix.spinnaker.front50.model.TemporarySQSQueue.java
License:Apache License
private TemporaryQueue createQueue(String snsTopicArn, String sqsQueueArn, String sqsQueueName) { String sqsQueueUrl = amazonSQS.createQueue(new CreateQueueRequest().withQueueName(sqsQueueName) .withAttributes(Collections.singletonMap("MessageRetentionPeriod", "60")) // 60s message retention ).getQueueUrl();//w ww .j a v a 2 s . co m log.info("Created Temporary S3 Notification Queue: {}", value("queue", sqsQueueUrl)); String snsTopicSubscriptionArn = amazonSNS.subscribe(snsTopicArn, "sqs", sqsQueueArn).getSubscriptionArn(); Statement snsStatement = new Statement(Statement.Effect.Allow).withActions(SQSActions.SendMessage); snsStatement.setPrincipals(Principal.All); snsStatement.setResources(Collections.singletonList(new Resource(sqsQueueArn))); snsStatement.setConditions(Collections.singletonList( new Condition().withType("ArnEquals").withConditionKey("aws:SourceArn").withValues(snsTopicArn))); Policy allowSnsPolicy = new Policy("allow-sns", Collections.singletonList(snsStatement)); HashMap<String, String> attributes = new HashMap<>(); attributes.put("Policy", allowSnsPolicy.toJson()); amazonSQS.setQueueAttributes(sqsQueueUrl, attributes); return new TemporaryQueue(snsTopicArn, sqsQueueArn, sqsQueueUrl, snsTopicSubscriptionArn); }
From source file:com.vitembp.embedded.interfaces.AmazonSQSControl.java
License:Open Source License
/** * Attempts to create the queue for this device. *//*from w ww . j a v a2 s. c o m*/ private void createQueue() { // if the queue was not yet created if (this.queueUrl == null) { // create the queue this.sqsClient.createQueue(new CreateQueueRequest().withQueueName(this.queueName) .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20")); // save the url for use when acknowledging messages this.queueUrl = this.sqsClient.getQueueUrl(this.queueName).getQueueUrl(); } }
From source file:edu.iit.sqs.ReceivingQueue.java
/** * *///from w ww .j a v a 2s.c o m public void createQueue() { for (int i = 0; i < RECQUEUENAMES.length; i++) { CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(RECQUEUENAMES[i]); myQueueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); ///Region usWest2 = Region.getRegion(Regions.US_WEST_2); //sqs.setRegion(usWest2); DOA doa = new DOA(); doa.addEc2Queue(myQueueUrl, ""); } }