com.amazonaws.services.sqs.model.ListQueuesResult Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.ListQueuesResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestSQSEventQueueProvider.java From conductor with Apache License 2.0 | 6 votes |
@Test public void testGetQueueWithCustomConfiguration() { when(configuration.getIntProperty(eq("workflow.event.queues.sqs.batchSize"), anyInt())).thenReturn(10); when(configuration.getIntProperty(eq("workflow.event.queues.sqs.pollTimeInMS"), anyInt())).thenReturn(50); when(configuration.getIntProperty(eq("workflow.event.queues.sqs.visibilityTimeoutInSeconds"), anyInt())).thenReturn(30); ListQueuesResult listQueuesResult = new ListQueuesResult().withQueueUrls("test_queue_1"); when(amazonSQSClient.listQueues(any(ListQueuesRequest.class))).thenReturn(listQueuesResult); SQSEventQueueProvider sqsEventQueueProvider = new SQSEventQueueProvider(amazonSQSClient, configuration); SQSObservableQueue sqsObservableQueue = (SQSObservableQueue) sqsEventQueueProvider.getQueue("test_queue_1"); assertNotNull(sqsObservableQueue); assertEquals(10, sqsObservableQueue.getBatchSize()); assertEquals(50, sqsObservableQueue.getPollTimeInMS()); assertEquals(30, sqsObservableQueue.getVisibilityTimeoutInSeconds()); }
Example #2
Source File: SpringLocalstackDockerRunnerTest.java From spring-localstack with Apache License 2.0 | 5 votes |
@Test public void testSQS() throws Exception { AmazonSQS client = amazonDockerClientsHolder.amazonSQS(); Map<String, String> attributeMap = new HashMap<>(); attributeMap.put("DelaySeconds", "0"); attributeMap.put("MaximumMessageSize", "262144"); attributeMap.put("MessageRetentionPeriod", "1209600"); attributeMap.put("ReceiveMessageWaitTimeSeconds", "20"); attributeMap.put("VisibilityTimeout", "30"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("test-queue").withAttributes(attributeMap); client.createQueue(createQueueRequest); ListQueuesResult listQueuesResult = client.listQueues(); assertThat(listQueuesResult.getQueueUrls().size(), is(1)); SQSConnection connection = createSQSConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("test-queue"); MessageProducer producer = session.createProducer(queue); TextMessage message = session.createTextMessage("Hello World!"); producer.send(message); MessageConsumer consumer = session.createConsumer(queue); TextMessage received = (TextMessage) consumer.receive(); assertThat(received.getText(), is("Hello World!")); }
Example #3
Source File: MockSQS.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Override public ListQueuesResult listQueues(ListQueuesRequest request) { String prefix = request.getQueueNamePrefix(); String searchPrefix = prefix == null ? "" : prefix; List<String> queueUrls = queues.keySet().stream() .filter(name -> name.startsWith(searchPrefix)) .map(name -> accountPrefix + name) .collect(Collectors.toList()); return new ListQueuesResult().withQueueUrls(queueUrls); }
Example #4
Source File: AWSSQSMetaDataExtension.java From syndesis with Apache License 2.0 | 5 votes |
@Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSQSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSQS sqsClient = clientBuilder.build(); List<String> attributeNames = new ArrayList<String>(); attributeNames.add("All"); try { ListQueuesResult result = sqsClient.listQueues(); Set<String> setQueue = new HashSet<String>(); if (result.getQueueUrls() != null) { for (String entry : result.getQueueUrls()) { GetQueueAttributesRequest req = new GetQueueAttributesRequest(); req.setQueueUrl(entry); req.setAttributeNames(attributeNames); GetQueueAttributesResult c = sqsClient.getQueueAttributes(req); setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name())); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setQueue).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing queues with has failed.", e); } }
Example #5
Source File: SQSObservableQueue.java From conductor with Apache License 2.0 | 5 votes |
private List<String> listQueues(String queueName) { ListQueuesRequest listQueuesRequest = new ListQueuesRequest().withQueueNamePrefix(queueName); ListQueuesResult resultList = client.listQueues(listQueuesRequest); return resultList.getQueueUrls().stream() .filter(queueUrl -> queueUrl.contains(queueName)) .collect(Collectors.toList()); }
Example #6
Source File: TestSQSObservableQueue.java From conductor with Apache License 2.0 | 5 votes |
@Test public void testException() { com.amazonaws.services.sqs.model.Message message = new com.amazonaws.services.sqs.model.Message().withMessageId("test") .withBody("") .withReceiptHandle("receiptHandle"); Answer<?> answer = (Answer<ReceiveMessageResult>) invocation -> new ReceiveMessageResult(); AmazonSQSClient client = mock(AmazonSQSClient.class); when(client.listQueues(any(ListQueuesRequest.class))).thenReturn(new ListQueuesResult().withQueueUrls("junit_queue_url")); when(client.receiveMessage(any(ReceiveMessageRequest.class))).thenThrow(new RuntimeException("Error in SQS communication")) .thenReturn(new ReceiveMessageResult().withMessages(message)) .thenAnswer(answer); SQSObservableQueue queue = new SQSObservableQueue.Builder() .withQueueName("junit") .withClient(client).build(); List<Message> found = new LinkedList<>(); Observable<Message> observable = queue.observe(); assertNotNull(observable); observable.subscribe(found::add); Uninterruptibles.sleepUninterruptibly(1000, TimeUnit.MILLISECONDS); assertEquals(1, found.size()); }
Example #7
Source File: TestSQSEventQueueProvider.java From conductor with Apache License 2.0 | 5 votes |
@Test public void testGetQueueWithDefaultConfiguration() { when(configuration.getIntProperty(anyString(), anyInt())).thenAnswer(invocation -> invocation.getArguments()[1]); ListQueuesResult listQueuesResult = new ListQueuesResult().withQueueUrls("test_queue_1"); when(amazonSQSClient.listQueues(any(ListQueuesRequest.class))).thenReturn(listQueuesResult); SQSEventQueueProvider sqsEventQueueProvider = new SQSEventQueueProvider(amazonSQSClient, configuration); SQSObservableQueue sqsObservableQueue = (SQSObservableQueue) sqsEventQueueProvider.getQueue("test_queue_1"); assertNotNull(sqsObservableQueue); assertEquals(1, sqsObservableQueue.getBatchSize()); assertEquals(100, sqsObservableQueue.getPollTimeInMS()); assertEquals(60, sqsObservableQueue.getVisibilityTimeoutInSeconds()); }
Example #8
Source File: SQSTestBase.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
/** * Each test creates its own uniquely named queue in SQS and then deletes it afterwards. * We try to scrub any leftover queues from the previous runs just in case tests were * aborted * * @param currentQueueNamePrefix */ public void generateCurrentQueueName(String currentQueueNamePrefix) { if (validateTestCreds()) { ListQueuesResult list = sqs.listQueues(currentQueueNamePrefix); for (String url : list.getQueueUrls()) { sqs.deleteQueue(url); } } this.currentQueueName = currentQueueNamePrefix + System.currentTimeMillis(); }
Example #9
Source File: AmazonSQSStubTest.java From aws-java-sdk-stubs with Apache License 2.0 | 5 votes |
@Test public void createQueue() { final String queueName = "bizo"; final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName); sqs.createQueue(createQueueRequest); final ListQueuesResult listQueuesResult = sqs.listQueues(); assertThat(listQueuesResult.getQueueUrls(), hasItem(containsString(queueName))); }
Example #10
Source File: TOCQueue.java From s3-bucket-loader with Apache License 2.0 | 5 votes |
/** * Note here we attempt to the TOCQueue which may take some time to be shown as available * @param isConsumer * @param maxAttempts * @throws Exception */ public void connectToQueue(boolean isConsumer, int maxAttempts) throws Exception{ for (int i=0; i<maxAttempts; i++) { logger.debug("connectToQueue() attempt: " + (i+1)); ListQueuesResult queuesResult = sqsClient.listQueues(); if (queuesResult != null) { for (String queueUrl : queuesResult.getQueueUrls()) { if (queueUrl.indexOf(sqsQueueName) != -1) { tocQueueUrl = queueUrl; break; } } } // if consumer, retry, otherwise is master, so just exit quick to create... if (tocQueueUrl == null && isConsumer) { Thread.currentThread().sleep(1000); continue; } else { break; // exit; } } if (tocQueueUrl == null && !isConsumer) { CreateQueueResult createQueueResult = sqsClient.createQueue(sqsQueueName); this.tocQueueUrl = createQueueResult.getQueueUrl(); } else if (tocQueueUrl == null) { throw new Exception("TOCQueue() isConsumer:"+ isConsumer+ " cannot start, sqsQueueName has yet to be created by master?: " + sqsQueueName); } }
Example #11
Source File: AbstractAmazonSQSClientWrapper.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 4 votes |
@Override public ListQueuesResult listQueues(ListQueuesRequest request) { request.getRequestClientOptions().appendUserAgent(userAgent); return amazonSqsToBeExtended.listQueues(request); }
Example #12
Source File: Sqs.java From sqs-exporter with Apache License 2.0 | 4 votes |
@Override public List<MetricFamilySamples> collect() { List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); try { if (sqs == null) { String region = new DefaultAwsRegionProviderChain().getRegion(); sqs = AmazonSQSClientBuilder .standard() .withRegion(region) .build(); logger.info("AmazonSQS client is connected to region: ({})", region); } List<String> queueUrls; // check for manually-specified queue name filters String queueUrlsFromEnv = System.getenv("SQS_QUEUE_URLS"); String queueNames = System.getenv("SQS_QUEUE_NAMES"); String queueNamePrefix = System.getenv("SQS_QUEUE_NAME_PREFIX"); if (queueUrlsFromEnv != null) { String[] urls = queueUrlsFromEnv.split(","); queueUrls = new ArrayList<String>(); for(String url : urls) { queueUrls.add(url); } } else if (queueNames != null) { // find the URLs for the named queues String[] names = queueNames.split(","); queueUrls = new ArrayList<String>(); for(String name : names) { queueUrls.add(sqs.getQueueUrl(name).getQueueUrl()); } } else { // get URLs for all queues visible to this account (with prefix if specified) ListQueuesResult queues = sqs.listQueues(queueNamePrefix); //If null is passed in the whole unfiltered list is returned queueUrls = queues.getQueueUrls(); } for (String qUrl : queueUrls) { String[] tokens = qUrl.split("\\/"); String queueName = tokens[tokens.length - 1]; GetQueueAttributesResult attr = sqs.getQueueAttributes(qUrl, attributeNames); Map<String, String> qAttributes = attr.getAttributes(); for (String key : qAttributes.keySet()) { GaugeMetricFamily labeledGauge = new GaugeMetricFamily( String.format("sqs_%s", key.toLowerCase().trim()), attributeDescriptions.get(key), Arrays.asList("queue")); labeledGauge.addMetric(Arrays.asList(queueName), Double.valueOf(qAttributes.get(key))); mfs.add(labeledGauge); } } } catch (AmazonClientException e) { logger.error(e.getMessage()); if (sqs != null) sqs.shutdown(); sqs = null; // force reconnect } return mfs; }
Example #13
Source File: BeanstalkConnector.java From cloudml with GNU Lesser General Public License v3.0 | 4 votes |
public List<String> listQueues(){ ListQueuesResult result= sqsClient.listQueues(); return result.getQueueUrls(); }
Example #14
Source File: AmazonSQSExtendedClientBase.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 2 votes |
/** * <p> * Returns a list of your queues. The maximum number of queues that can be * returned is 1000. If you specify a value for the optional * <code>QueueNamePrefix</code> parameter, only queues with a name beginning * with the specified value are returned. * </p> * * @param listQueuesRequest * Container for the necessary parameters to execute the * ListQueues service method on AmazonSQS. * * @return The response from the ListQueues service method, as returned by * AmazonSQS. * * * @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. */ public ListQueuesResult listQueues(ListQueuesRequest listQueuesRequest) throws AmazonServiceException, AmazonClientException { return amazonSqsToBeExtended.listQueues(listQueuesRequest); }
Example #15
Source File: AmazonSQSExtendedClientBase.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 2 votes |
/** * <p> * Returns a list of your queues. The maximum number of queues that can be * returned is 1000. If you specify a value for the optional * <code>QueueNamePrefix</code> parameter, only queues with a name beginning * with the specified value are returned. * </p> * * @return The response from the ListQueues service method, as returned by * AmazonSQS. * * * @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. */ public ListQueuesResult listQueues() throws AmazonServiceException, AmazonClientException { return amazonSqsToBeExtended.listQueues(); }
Example #16
Source File: AmazonSQSExtendedClientBase.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 2 votes |
/** * <p> * Returns a list of your queues. The maximum number of queues that can be * returned is 1000. If you specify a value for the optional * <code>QueueNamePrefix</code> parameter, only queues with a name beginning * with the specified value are returned. * </p> * * @param queueNamePrefix * A string to use for filtering the list results. Only those * queues whose name begins with the specified string are * returned. * * @return The response from the ListQueues service method, as returned by * AmazonSQS. * * * @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. */ public ListQueuesResult listQueues(String queueNamePrefix) throws AmazonServiceException, AmazonClientException { return amazonSqsToBeExtended.listQueues(queueNamePrefix); }