List of usage examples for com.amazonaws.services.sqs.model GetQueueUrlRequest GetQueueUrlRequest
public GetQueueUrlRequest(String queueName)
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
License:Open Source License
/** * Check if the requested queue exists. This function calls * <code>GetQueueUrl</code> for the given queue name, returning true on * success, false if it gets <code>QueueDoesNotExistException</code>. * /*from www . j a v a 2 s .c o m*/ * @param queueName * the queue to check * @return true if the queue exists, false if it doesn't. * @throws JMSException */ public boolean queueExists(String queueName) throws JMSException { try { amazonSQSClient.getQueueUrl(new GetQueueUrlRequest(queueName)); return true; } catch (QueueDoesNotExistException e) { return false; } catch (AmazonClientException e) { throw handleException(e, "getQueueUrl"); } }
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
License:Open Source License
/** * Check if the requested queue exists. This function calls * <code>GetQueueUrl</code> for the given queue name with the given owner * accountId, returning true on success, false if it gets * <code>QueueDoesNotExistException</code>. * /* ww w .j a v a 2s . com*/ * @param queueName * the queue to check * @param queueOwnerAccountId * The AWS accountId of the account that created the queue * @return true if the queue exists, false if it doesn't. * @throws JMSException */ public boolean queueExists(String queueName, String queueOwnerAccountId) throws JMSException { try { GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName); getQueueUrlRequest.setQueueOwnerAWSAccountId(queueOwnerAccountId); amazonSQSClient.getQueueUrl(getQueueUrlRequest); return true; } catch (QueueDoesNotExistException e) { return false; } catch (AmazonClientException e) { throw handleException(e, "getQueueUrl"); } }
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
License:Open Source License
/** * Gets the queueUrl of a queue given a queue name. * //from w w w . j a va 2 s . co m * @param queueName * @return The response from the GetQueueUrl service method, as returned by * AmazonSQS, which will include queue`s URL * @throws JMSException */ public GetQueueUrlResult getQueueUrl(String queueName) throws JMSException { return getQueueUrl(new GetQueueUrlRequest(queueName)); }
From source file:com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.java
License:Open Source License
/** * Gets the queueUrl of a queue given a queue name owned by the provided accountId. * /*ww w . j a v a2 s. co m*/ * @param queueName * @param queueOwnerAccountId The AWS accountId of the account that created the queue * @return The response from the GetQueueUrl service method, as returned by * AmazonSQS, which will include queue`s URL * @throws JMSException */ public GetQueueUrlResult getQueueUrl(String queueName, String queueOwnerAccountId) throws JMSException { GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueName); getQueueUrlRequest.setQueueOwnerAWSAccountId(queueOwnerAccountId); return getQueueUrl(getQueueUrlRequest); }
From source file:com.athena.sqs.MessageContext.java
License:Apache License
/** * Gets real queue url from SQS//from www. j a v a 2 s . co m * @param queueName name of the queue * @return real queue name * @throws MessageException */ public String getQueue(String queueName) throws MessageException { String queueUrl = null; try { queueUrl = queueNameMap.get(queueName); if (queueUrl != null) return queueUrl; // If queue name is not exist, lookup queue. GetQueueUrlRequest queue = new GetQueueUrlRequest(queueName); GetQueueUrlResult queueResult = sqsClient.getQueueUrl(queue); queueUrl = queueResult.getQueueUrl(); } catch (AmazonServiceException ase) { throw ase; } catch (AmazonClientException ace) { throw ace; } return queueUrl; }
From source file:com.clicktravel.infrastructure.messaging.aws.sqs.DefaultSqsQueueResourceFactory.java
License:Apache License
@Override public SqsQueueResource createSqsQueueResource(final String name) { final String queueUrl = amazonSqsClient.getQueueUrl(new GetQueueUrlRequest(name)).getQueueUrl(); logger.info("Using existing SQS queue: " + name); final SqsQueueResource sqsQueueResource = new SqsQueueResource(name, queueUrl, amazonSqsClient); return sqsQueueResource; }
From source file:com.comcast.cns.tools.CQSHandler.java
License:Apache License
public static synchronized void ensureQueuesExist(String queueNamePrefix, int numShards) { for (int i = 0; i < numShards; i++) { GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(queueNamePrefix + i); try {/* w w w . j av a 2 s . c om*/ sqs.getQueueUrl(getQueueUrlRequest); } catch (AmazonServiceException ex) { if (ex.getStatusCode() == 400) { CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueNamePrefix + i); Map<String, String> attributes = new HashMap<String, String>(); if (queueNamePrefix .startsWith(CMBProperties.getInstance().getCNSEndpointPublishQueueNamePrefix())) { attributes.put("VisibilityTimeout", CMBProperties.getInstance().getCNSEndpointPublishJobVisibilityTimeout() + ""); } else { attributes.put("VisibilityTimeout", CMBProperties.getInstance().getCNSPublishJobVisibilityTimeout() + ""); } createQueueRequest.setAttributes(attributes); CreateQueueResult createQueueResponse = sqs.createQueue(createQueueRequest); if (createQueueResponse.getQueueUrl() == null) { throw new IllegalStateException("Could not create queue with name " + queueNamePrefix + i); } logger.info("event=created_missing_queue name=" + queueNamePrefix + i + " url=" + createQueueResponse.getQueueUrl()); } else { throw ex; } } } }
From source file:com.dateofrock.aws.simplesqs.JobConsumer.java
License:Apache License
public void consume(Class<? extends AbstractJobTicket> clazz) { String queueName = this.reflector.findQueueName(clazz); GetQueueUrlResult result = this.sqs.getQueueUrl(new GetQueueUrlRequest(queueName)); String queueUrl = result.getQueueUrl(); ReceiveMessageResult receivedMessage = this.sqs.receiveMessage( new ReceiveMessageRequest(queueUrl).withMaxNumberOfMessages(this.maxNumberOfMessages)); List<Message> messages = receivedMessage.getMessages(); for (Message message : messages) { String jobId = message.getBody(); String receiptHandle = message.getReceiptHandle(); AbstractJobTicket jobTicket = null; try {//from www .j a v a2 s .com jobTicket = this.sdbMapper.load(clazz, jobId); jobTicket.receiptHandle = receiptHandle; } catch (SimpleDBMapperNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); // FIXME Message?? this.sqs.deleteMessage(new DeleteMessageRequest(queueUrl, receiptHandle)); return; } Status currentStatus = Status.fromJobTicket(jobTicket); switch (currentStatus) { case WAITING: jobTicket.status = Status.IN_PROGRESS.getValue(); jobTicket.updatedAt = new Date(); this.sdbMapper.save(jobTicket); try { // jobTicket.execute(); } catch (Exception e) { // StackTrace? StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); e.printStackTrace(printWriter); printWriter.flush(); printWriter.close(); try { writer.close(); } catch (IOException ignore) { } jobTicket.exceptionStackTrace = writer.toString(); jobTicket.status = Status.FAILURE.getValue(); jobTicket.updatedAt = new Date(); this.sdbMapper.save(jobTicket); break; } jobTicket.status = Status.SUCCESS.getValue(); jobTicket.updatedAt = new Date(); this.sdbMapper.save(jobTicket); break; case IN_PROGRESS: jobTicket.processIfInProgress(); break; case SUCCESS: break; case FAILURE: break; default: break; } } }
From source file:com.dateofrock.aws.simplesqs.JobProducer.java
License:Apache License
public void put(AbstractJobTicket jobTicket) { String queueName = this.reflector.findQueueName(jobTicket.getClass()); try {/*from w w w . j av a 2 s. com*/ jobTicket.prepare(); } catch (Exception e) { throw new SimpleSQSException(e); } Date now = new Date(); if (jobTicket.createdAt == null) { jobTicket.createdAt = now; } jobTicket.updatedAt = now; jobTicket.status = Status.WAITING.getValue(); this.sdbMapper.save(jobTicket); GetQueueUrlResult result = this.sqs.getQueueUrl(new GetQueueUrlRequest(queueName)); String queueUrl = result.getQueueUrl(); this.sqs.sendMessage(new SendMessageRequest(queueUrl, jobTicket.id)); }
From source file:com.dxc.temp.SimpleProducerConsumer.java
License:Open Source License
public static void main(String[] args) throws InterruptedException { int argIndex = 0; final String accessKey = args[argIndex++]; final String secretKey = args[argIndex++]; final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); final String endpoint = args[argIndex++]; final String queueName = args[argIndex++]; final int producerCount = Integer.parseInt(args[argIndex++]); final int consumerCount = Integer.parseInt(args[argIndex++]); final int batchSize = Integer.parseInt(args[argIndex++]); final int messageSizeByte = Integer.parseInt(args[argIndex++]); final int runTimeMinutes = Integer.parseInt(args[argIndex++]); // configure the SQS client with enough connections for all producer and // consumer threads AmazonSQS sqsClient = new AmazonSQSClient(credentials, new ClientConfiguration().withMaxConnections(producerCount + consumerCount)); sqsClient.setEndpoint(endpoint);/*from w w w. jav a 2 s. c o m*/ String queueUrl = sqsClient.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl(); // the flag to stop producer, consumer, and monitor threads AtomicBoolean stop = new AtomicBoolean(false); // start the producers final AtomicInteger producedCount = new AtomicInteger(); Thread[] producers = new Thread[producerCount]; for (int i = 0; i < producerCount; i++) { if (batchSize == 1) producers[i] = new Producer(sqsClient, queueUrl, messageSizeByte, producedCount, stop); else producers[i] = new BatchProducer(sqsClient, queueUrl, batchSize, messageSizeByte, producedCount, stop); producers[i].start(); } // start the consumers final AtomicInteger consumedCount = new AtomicInteger(); Thread[] consumers = new Thread[consumerCount]; for (int i = 0; i < consumerCount; i++) { if (batchSize == 1) consumers[i] = new Consumer(sqsClient, queueUrl, consumedCount, stop); else consumers[i] = new BatchConsumer(sqsClient, queueUrl, batchSize, consumedCount, stop); consumers[i].start(); } // start the monitor (thread) Thread monitor = new Monitor(producedCount, consumedCount, stop); monitor.start(); // wait for the specified amount of time then stop Thread.sleep(TimeUnit.MINUTES.toMillis(Math.min(runTimeMinutes, MAX_RUNTIME_MINUTES))); stop.set(true); // join all threads for (int i = 0; i < producerCount; i++) producers[i].join(); for (int i = 0; i < consumerCount; i++) consumers[i].join(); monitor.interrupt(); monitor.join(); }