public static void main(String[] args) { final String queue_name = "testQueue" + new Date().getTime(); AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); // first, create a queue (unless it exists already) try { CreateQueueResult cq_result = sqs.createQueue(queue_name); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } final String queue_url = sqs.getQueueUrl(queue_name).getQueueUrl(); // Send some messages to the queue for (int i = 0; i < 20; i++) { sqs.sendMessage(queue_url, "This is message " + i); } // change visibility timeout (single) changeMessageVisibilitySingle(queue_url, 3600); // change visibility timeout (multiple) changeMessageVisibilityMultiple(queue_url, 2000); } }
String queue_url = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
String dl_queue_url = sqs.getQueueUrl(dl_queue_name) .getQueueUrl(); String src_queue_url = sqs.getQueueUrl(src_queue_name) .getQueueUrl();
String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
/** * Gets the queueUrl of a queue given a queue name owned by the provided accountId. * * @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 { return getQueueUrl(new GetQueueUrlRequest(queueName).withQueueOwnerAWSAccountId(queueOwnerAccountId)); }
/** * Returns the SQS queue URL. * @param name queue name * @return the URL of the queue */ public static String getQueueURL(String name) { try { return getClient().getQueueUrl(name).getQueueUrl(); } catch (Exception e) { logger.info("Queue '{}' could not be found: {}", name, e.getMessage()); return null; } }
/** * Returns the SQS queue URL. * @param name queue name * @return the URL of the queue */ public static String getQueueURL(String name) { try { return getClient().getQueueUrl(name).getQueueUrl(); } catch (Exception e) { logger.info("Queue '{}' could not be found: {}", name, e.getMessage()); return null; } }
public void deleteQueue(String queueName) { LOG.info("Deleting SQS queue: {}", queueName); sqs.deleteQueue(sqs.getQueueUrl(queueName).getQueueUrl()); }
/** * Calls <code>getQueueUrl</code> and wraps <code>AmazonClientException</code> * * @param getQueueUrlRequest * Container for the necessary parameters to execute the * getQueueUrl service method on AmazonSQS. * @return The response from the GetQueueUrl service method, as returned by * AmazonSQS, which will include queue`s URL * @throws JMSException */ public GetQueueUrlResult getQueueUrl(GetQueueUrlRequest getQueueUrlRequest) throws JMSException { try { prepareRequest(getQueueUrlRequest); return amazonSQSClient.getQueueUrl(getQueueUrlRequest); } catch (AmazonClientException e) { throw handleException(e, "getQueueUrl"); } }
@Override public State call() { queueUrl = sqs.getQueueUrl(queueName).getQueueUrl(); request = new ReceiveMessageRequest(queueUrl) // .withWaitTimeSeconds(20) // .withMaxNumberOfMessages(10); return new State(new LinkedList<>()); }
private String getQueueUrl() { return sqsClient.getQueueUrl( new GetQueueUrlRequest().withQueueName(queueName)).getQueueUrl(); }
private String queryQueueUrl(String queueName) { try { return _sqs.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl(); } catch (QueueDoesNotExistException e) { // Create the queue int visibilityTimeout = queueName.equals(_pendingScanRangeQueue) ? DEFAULT_TASK_CLAIM_VISIBILITY_TIMEOUT : DEFAULT_TASK_COMPLETE_VISIBILITY_TIMEOUT; return _sqs.createQueue( new CreateQueueRequest(queueName) .withAttributes(ImmutableMap.<String, String>of( "VisibilityTimeout", String.valueOf(visibilityTimeout))) ).getQueueUrl(); } }
@Override public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS) { try { return amazonSQS.sendMessage(new SendMessageRequest().withQueueUrl(amazonSQS.getQueueUrl(queueName).getQueueUrl()).withMessageBody(messageText) .withMessageAttributes(messageAttributes)); } catch (QueueDoesNotExistException e) { throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName), e); } } }
/** * 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>. * * @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(prepareRequest(new GetQueueUrlRequest(queueName))); return true; } catch (QueueDoesNotExistException e) { return false; } catch (AmazonClientException e) { throw handleException(e, "getQueueUrl"); } }
@Override public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS) { try { return amazonSQS.sendMessage(new SendMessageRequest().withQueueUrl(amazonSQS.getQueueUrl(queueName).getQueueUrl()).withMessageBody(messageText) .withMessageAttributes(messageAttributes)); } catch (QueueDoesNotExistException e) { throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName), e); } } }
/** * Ensure that the queue exists and has a policy granting the source topic permission to send messages to it */ private static String ensureQueueExists(AmazonSQS amazonSQS, ARN queueARN, ARN topicARN) { String queueUrl; try { queueUrl = amazonSQS.getQueueUrl(queueARN.name).getQueueUrl(); } catch (Exception e) { queueUrl = amazonSQS.createQueue(queueARN.name).getQueueUrl(); } amazonSQS.setQueueAttributes( queueUrl, Collections.singletonMap("Policy", buildSQSPolicy(queueARN, topicARN).toJson()) ); return queueUrl; }
private static Flowable<SqsMessage> get(AmazonSQS sqs, String queueName, Optional<String> bucketName, Optional<AmazonS3> s3, Service service, int waitTimeSeconds,Consumer<? super String> logger) { return Flowable.defer(() -> { final String queueUrl = sqs.getQueueUrl(queueName).getQueueUrl(); return Flowable.just(sqs.receiveMessage(request(queueName, waitTimeSeconds)) // .getMessages() // .stream() // .map(m -> Sqs.getNextMessage(m, queueUrl, bucketName, s3, sqs, service)) // .collect(Collectors.toList())) // .concatWith(Flowable.defer(() -> Flowable.just(sqs.receiveMessage(request(queueName, 0)) // .getMessages() // .stream() // .map(m -> Sqs.getNextMessage(m, queueUrl, bucketName, s3, sqs, service)) // .collect(Collectors.toList()))) // .repeat()) .takeWhile(list -> !list.isEmpty()) // .flatMapIterable(x -> x) // .filter(opt -> opt.isPresent()) // .map(opt -> opt.get()); });// }
@Override protected void initSubscription(SubscriptionImpl<String> subscription) { for(TopicName topicName : subscription.getTopicNames()) { SubscriptionName subscriptionName = nameFactory_.getSubscriptionName(topicName, subscription.getSubscriptionId()); log_.info("Subscribing to " + subscriptionName + "..."); String queueUrl = //"https://sqs.us-west-2.amazonaws.com/189141687483/s2-bruce2-trace-monitor"; sqsClient_.getQueueUrl(subscriptionName.toString()).getQueueUrl(); SqsSubscriber subscriber = new SqsSubscriber(this, sqsClient_, queueUrl, subscriptionName.toString(), getTraceFactory(), subscription.getConsumer(), getCounter(), getBusyCounter(), nameFactory_.getTenantId()); subscribers_.add(subscriber); } }
private String ensureQueueExists(String queueName, Map<String, String> attributes) { final AmazonSQS sqsClient = getSQSClient(); try { return sqsClient.createQueue(new CreateQueueRequest(queueName).withAttributes(attributes)).getQueueUrl(); } catch (QueueNameExistsException e) { final String queueUrl = sqsClient.getQueueUrl(queueName).getQueueUrl(); sqsClient.setQueueAttributes(new SetQueueAttributesRequest(queueUrl, attributes)); return queueUrl; } }
@Override public String resolveDestination(String name) throws DestinationResolutionException { String queueName = name; if (this.resourceIdResolver != null) { queueName = this.resourceIdResolver.resolveToPhysicalResourceId(name); } if (isValidQueueUrl(queueName)) { return queueName; } if (this.autoCreate) { //Auto-create is fine to be called even if the queue exists. CreateQueueResult createQueueResult = this.amazonSqs.createQueue(new CreateQueueRequest(queueName)); return createQueueResult.getQueueUrl(); } else { try { GetQueueUrlResult getQueueUrlResult = this.amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueName)); return getQueueUrlResult.getQueueUrl(); } catch (QueueDoesNotExistException e) { throw new DestinationResolutionException(e.getMessage(), e); } } }