当前位置: 首页>>代码示例>>Java>>正文


Java GetQueueAttributesResult类代码示例

本文整理汇总了Java中com.amazonaws.services.sqs.model.GetQueueAttributesResult的典型用法代码示例。如果您正苦于以下问题:Java GetQueueAttributesResult类的具体用法?Java GetQueueAttributesResult怎么用?Java GetQueueAttributesResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GetQueueAttributesResult类属于com.amazonaws.services.sqs.model包,在下文中一共展示了GetQueueAttributesResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkQueueLength

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
private void checkQueueLength() {
  try {
    GetQueueAttributesResult
        result =
        sqsClient.getQueueAttributes(queueUrl, Arrays.asList(QUEUELENGTHATTR,
            QUEUEINVISIBLEATTR));
    Map<String, String> attrs = result.getAttributes();

    if (attrs.containsKey(QUEUELENGTHATTR)) {
      Stats.addMetric(StatsUtil.getStatsName("healthcheck", "ec2queue_length"),
          Integer.parseInt(attrs.get(QUEUELENGTHATTR)));
      logger.info("Ec2 queue length is {}", attrs.get(QUEUELENGTHATTR));
    }

    if (attrs.containsKey(QUEUEINVISIBLEATTR)) {
      Stats.addMetric(StatsUtil.getStatsName("healthcheck", "ec2queue_in_processing"),
          Integer.parseInt(attrs.get("ApproximateNumberOfMessagesNotVisible")));
      logger.info("Ec2 queue in processing length is {}", attrs.get(QUEUEINVISIBLEATTR));
    }

  } catch (Exception ex) {
    logger.warn(ExceptionUtils.getRootCauseMessage(ex));
    logger.warn(ExceptionUtils.getFullStackTrace(ex));
  }

}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:27,代码来源:HealthCheckJob.java

示例2: testGet

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void testGet() {
    // given
    QueueName qn = new QueueName("q1");
    GetQueueUrlResult queueUrlResult = mock(GetQueueUrlResult.class);
    when(queueUrlResult.getQueueUrl()).thenReturn("url1");
    GetQueueAttributesResult attributesResult = mock(GetQueueAttributesResult.class);
    HashMap<String, String> attributes = new HashMap<>();
    attributes.put("1", "3");
    attributes.put("hi", "ho");
    when(attributesResult.getAttributes()).thenReturn(attributes);
    when(amazonSQS.getQueueUrl(any(GetQueueUrlRequest.class))).thenReturn(queueUrlResult);
    when(amazonSQS.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(
            attributesResult);

    // when
    Queue queue = uut.get(qn);

    // then
    assertEquals("url1", queue.getUrl());
    assertEquals("q1", queue.getName().getId());
    assertEquals(attributes, queue.getQueueAttributes());

}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:25,代码来源:QueueFactoryTest.java

示例3: testShouldReturnTotalNumberOfFailedEvents

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void testShouldReturnTotalNumberOfFailedEvents() {

    final SdkHttpMetadata responseMetadata = mock(SdkHttpMetadata.class);
    when(responseMetadata.getHttpStatusCode()).thenReturn(200);

    final String totalNumberOfFailedEvents = RandomStringUtils.randomNumeric(4);
    final Map<String, String> attributes = new HashMap<>();
    attributes.put(QueueAttributeName.ApproximateNumberOfMessages.name(), totalNumberOfFailedEvents);

    final GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult();
    getQueueAttributesResult.setSdkHttpMetadata(responseMetadata);
    getQueueAttributesResult.setAttributes(attributes);

    when(amazonSQS.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(getQueueAttributesResult);

    assertThat(sqsFailedEventSource.getSize()).isEqualTo(Long.valueOf(totalNumberOfFailedEvents));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:19,代码来源:SQSFailedEventSourceTest.java

示例4: addPermissions

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
private void addPermissions() {
	if (permissions != null && permissions.isEmpty() == false) {
		GetQueueAttributesResult result = sqsClient
				.getQueueAttributes(new GetQueueAttributesRequest(queueUrl,
						Arrays.asList("Policy")));

		AwsUtil.addPermissions(result.getAttributes(), permissions,
				new AwsUtil.AddPermissionHandler() {

					@Override
					public void execute(Permission p) {
						sqsClient.addPermission(new AddPermissionRequest()
								.withQueueUrl(queueUrl)
								.withLabel(p.getLabel())
								.withAWSAccountIds(p.getAwsAccountIds())
								.withActions(p.getActions()));
					}
				});
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:21,代码来源:SqsExecutor.java

示例5: BufferedStringSqsQueueTest

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
public BufferedStringSqsQueueTest() {
    queue.setSendMessageTaskBuffer(sendMessageTaskBufferMock);
    queue.setDeleteMessageTaskBuffer(deleteMessageTaskBufferMock);
    queue.setChangeMessageVisibilityTaskBuffer(changeMessageVisibilityTaskBufferMock);

    when(requestSenderMock.sendRequest(any(GetQueueAttributesAction.class))).thenReturn(Single.just(
            new GetQueueAttributesResult().withAttributes(MutableSqsQueueAttributesTest.ATTRIBUTE_STRING_MAP)
    ));
    when(requestSenderMock.sendRequest(any(ReceiveMessagesAction.class))).thenReturn(Single.just(
            new ReceiveMessageResult().withMessages(SQS_MESSAGE)
    ));
}
 
开发者ID:Bandwidth,项目名称:async-sqs,代码行数:13,代码来源:BufferedStringSqsQueueTest.java

示例6: size

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Override
public long size() {
	GetQueueAttributesResult attributes = client.getQueueAttributes(queueURL, Arrays.asList("ApproximateNumberOfMessages"));
	String sizeAsStr = attributes.getAttributes().get("ApproximateNumberOfMessages");
	try {
		return Long.parseLong(sizeAsStr);
	} catch(Exception e) {
		return -1;
	}
}
 
开发者ID:Netflix,项目名称:conductor,代码行数:11,代码来源:SQSObservableQueue.java

示例7: getSize

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Override
public long getSize() {

    final GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest(queueUrl,
            Collections.singletonList(QueueAttributeName.ApproximateNumberOfMessages.name()));

    final GetQueueAttributesResult queueAttributes = amazonSQS.getQueueAttributes(getQueueAttributesRequest);

    if (queueAttributes.getAttributes() != null) {
        return Long.valueOf(queueAttributes.getAttributes().getOrDefault(
                    QueueAttributeName.ApproximateNumberOfMessages.name(), "0"));
    } else {
        return 0L;
    }
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:16,代码来源:SQSFailedEventSource.java

示例8: testShouldReturnDefaultTotalNumberOfFailedEvents

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void testShouldReturnDefaultTotalNumberOfFailedEvents() {
    final SdkHttpMetadata responseMetadata = mock(SdkHttpMetadata.class);
    when(responseMetadata.getHttpStatusCode()).thenReturn(200);

    final GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult();
    getQueueAttributesResult.setSdkHttpMetadata(responseMetadata);
    getQueueAttributesResult.setAttributes(new HashMap<>());

    when(amazonSQS.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(getQueueAttributesResult);
    assertThat(sqsFailedEventSource.getSize()).isEqualTo(Long.valueOf(0L));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:13,代码来源:SQSFailedEventSourceTest.java

示例9: testShouldReturnDefaultTotalNumberOfFailedEventsWhenThereIsNoQueueAttributes

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void testShouldReturnDefaultTotalNumberOfFailedEventsWhenThereIsNoQueueAttributes() {
    final SdkHttpMetadata responseMetadata = mock(SdkHttpMetadata.class);
    when(responseMetadata.getHttpStatusCode()).thenReturn(200);

    final GetQueueAttributesResult getQueueAttributesResult = new GetQueueAttributesResult();
    getQueueAttributesResult.setSdkHttpMetadata(responseMetadata);
    when(amazonSQS.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(getQueueAttributesResult);
    assertThat(sqsFailedEventSource.getSize()).isEqualTo(Long.valueOf(0L));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:11,代码来源:SQSFailedEventSourceTest.java

示例10: getNumMessages

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
/**
 * Return the approximate number of visible messages in an SQS queue.
 *
 * @param client
 *            SQS client
 * @param queueUrl
 *            Queue URL
 * @return approximate number of visible messages
 */
private int getNumMessages() {
    try {
        final GetQueueAttributesResult result = sqs
                .getQueueAttributes(new GetQueueAttributesRequest(queueUrl)
                        .withAttributeNames(NUM_MESSAGES_KEY));
        final int count = Integer.parseInt(
                result.getAttributes().getOrDefault(NUM_MESSAGES_KEY, "0"));
        LOGGER.info("Approximately {} messages in queue", count);
        return count;
    } catch (Exception e) {
        LOGGER.error("Unable to get approximate number of messages", e);
    }
    return 0;
}
 
开发者ID:smoketurner,项目名称:pipeline,代码行数:24,代码来源:AmazonSQSIterator.java

示例11: testWithDefaultTaskExecutorAndOneHandler

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void testWithDefaultTaskExecutorAndOneHandler() throws Exception {
    int testedMaxNumberOfMessages = 10;

    Map<QueueMessageHandler.MappingInformation, HandlerMethod> messageHandlerMethods = Collections.singletonMap(
            new QueueMessageHandler.MappingInformation(Collections.singleton("testQueue"),
                    SqsMessageDeletionPolicy.ALWAYS), null);

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();

    QueueMessageHandler mockedHandler = mock(QueueMessageHandler.class);
    AmazonSQSAsync mockedSqs = mock(AmazonSQSAsync.class, withSettings().stubOnly());

    when(mockedSqs.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(new GetQueueAttributesResult());
    when(mockedSqs.getQueueUrl(any(GetQueueUrlRequest.class))).thenReturn(new GetQueueUrlResult().withQueueUrl("testQueueUrl"));
    when(mockedHandler.getHandlerMethods()).thenReturn(messageHandlerMethods);

    container.setMaxNumberOfMessages(testedMaxNumberOfMessages);
    container.setAmazonSqs(mockedSqs);
    container.setMessageHandler(mockedHandler);

    container.afterPropertiesSet();

    int expectedPoolMaxSize = messageHandlerMethods.size() * (testedMaxNumberOfMessages + 1);

    ThreadPoolTaskExecutor taskExecutor = (ThreadPoolTaskExecutor) container.getTaskExecutor();
    assertNotNull(taskExecutor);
    assertEquals(expectedPoolMaxSize, taskExecutor.getMaxPoolSize());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:30,代码来源:SimpleMessageListenerContainerTest.java

示例12: amazonSQS

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Bean
public AmazonSQSAsync amazonSQS() {
    AmazonSQSAsync mockAmazonSQS = mock(AmazonSQSAsync.class, withSettings().stubOnly());
    mockGetQueueUrl(mockAmazonSQS, "testQueue", "http://testQueue.amazonaws.com");
    when(mockAmazonSQS.receiveMessage(any(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult());
    when(mockAmazonSQS.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(new GetQueueAttributesResult());
    return mockAmazonSQS;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:9,代码来源:SimpleMessageListenerContainerTest.java

示例13: receiveMessageRequests_withOneElement_created

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void receiveMessageRequests_withOneElement_created() throws Exception {
    AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer();

    AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly());
    QueueMessageHandler messageHandler = new QueueMessageHandler();
    container.setAmazonSqs(mock);
    container.setMessageHandler(mock(QueueMessageHandler.class));
    container.setMessageHandler(messageHandler);
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    applicationContext.registerSingleton("messageListener", MessageListener.class);
    container.setMaxNumberOfMessages(11);
    container.setVisibilityTimeout(22);
    container.setWaitTimeOut(33);

    messageHandler.setApplicationContext(applicationContext);

    when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))).
            thenReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com"));
    when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(new GetQueueAttributesResult());

    messageHandler.afterPropertiesSet();
    container.afterPropertiesSet();
    container.start();

    Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues();
    assertEquals("http://testQueue.amazonaws.com", registeredQueues.get("testQueue").getReceiveMessageRequest().getQueueUrl());
    assertEquals(11L, registeredQueues.get("testQueue").getReceiveMessageRequest().getMaxNumberOfMessages().longValue());
    assertEquals(22L, registeredQueues.get("testQueue").getReceiveMessageRequest().getVisibilityTimeout().longValue());
    assertEquals(33L, registeredQueues.get("testQueue").getReceiveMessageRequest().getWaitTimeSeconds().longValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:32,代码来源:MessageListenerContainerTest.java

示例14: receiveMessageRequests_withMultipleElements_created

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void receiveMessageRequests_withMultipleElements_created() throws Exception {
    AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer();

    AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly());
    container.setAmazonSqs(mock);
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    QueueMessageHandler messageHandler = new QueueMessageHandler();
    messageHandler.setApplicationContext(applicationContext);
    container.setMessageHandler(messageHandler);
    applicationContext.registerSingleton("messageListener", MessageListener.class);
    applicationContext.registerSingleton("anotherMessageListener", AnotherMessageListener.class);

    container.setMaxNumberOfMessages(11);
    container.setVisibilityTimeout(22);
    container.setWaitTimeOut(33);

    when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))).
            thenReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com"));
    when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("anotherTestQueue"))).
            thenReturn(new GetQueueUrlResult().withQueueUrl("http://anotherTestQueue.amazonaws.com"));
    when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(new GetQueueAttributesResult());

    messageHandler.afterPropertiesSet();
    container.afterPropertiesSet();
    container.start();

    Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues();
    assertEquals("http://testQueue.amazonaws.com", registeredQueues.get("testQueue").getReceiveMessageRequest().getQueueUrl());
    assertEquals(11L, registeredQueues.get("testQueue").getReceiveMessageRequest().getMaxNumberOfMessages().longValue());
    assertEquals(22L, registeredQueues.get("testQueue").getReceiveMessageRequest().getVisibilityTimeout().longValue());
    assertEquals(33L, registeredQueues.get("testQueue").getReceiveMessageRequest().getWaitTimeSeconds().longValue());
    assertEquals("http://anotherTestQueue.amazonaws.com", registeredQueues.get("anotherTestQueue").getReceiveMessageRequest().getQueueUrl());
    assertEquals(11L, registeredQueues.get("anotherTestQueue").getReceiveMessageRequest().getMaxNumberOfMessages().longValue());
    assertEquals(22L, registeredQueues.get("anotherTestQueue").getReceiveMessageRequest().getVisibilityTimeout().longValue());
    assertEquals(33L, registeredQueues.get("anotherTestQueue").getReceiveMessageRequest().getWaitTimeSeconds().longValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:38,代码来源:MessageListenerContainerTest.java

示例15: receiveMessageRequests_withDestinationResolverThrowingException_shouldLogWarningAndNotCreateRequest

import com.amazonaws.services.sqs.model.GetQueueAttributesResult; //导入依赖的package包/类
@Test
public void receiveMessageRequests_withDestinationResolverThrowingException_shouldLogWarningAndNotCreateRequest() throws Exception {
    // Arrange
    AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer();
    Logger loggerMock = container.getLogger();

    AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly());
    container.setAmazonSqs(mock);
    StaticApplicationContext applicationContext = new StaticApplicationContext();
    QueueMessageHandler messageHandler = new QueueMessageHandler();
    messageHandler.setApplicationContext(applicationContext);
    container.setMessageHandler(messageHandler);
    applicationContext.registerSingleton("messageListener", MessageListener.class);
    applicationContext.registerSingleton("anotherMessageListener", AnotherMessageListener.class);

    when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))).
            thenThrow(new DestinationResolutionException("Queue not found"));
    when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("anotherTestQueue"))).
            thenReturn(new GetQueueUrlResult().withQueueUrl("http://anotherTestQueue.amazonaws.com"));
    when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))).thenReturn(new GetQueueAttributesResult());

    messageHandler.afterPropertiesSet();
    container.afterPropertiesSet();

    // Act
    container.start();

    // Assert
    ArgumentCaptor<String> logMsgArgCaptor = ArgumentCaptor.forClass(String.class);
    verify(loggerMock).warn(logMsgArgCaptor.capture());
    Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues();
    assertFalse(registeredQueues.containsKey("testQueue"));
    assertEquals("Ignoring queue with name 'testQueue' as it does not exist.", logMsgArgCaptor.getValue());
    assertEquals("http://anotherTestQueue.amazonaws.com", registeredQueues.get("anotherTestQueue").getReceiveMessageRequest().getQueueUrl());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:36,代码来源:MessageListenerContainerTest.java


注:本文中的com.amazonaws.services.sqs.model.GetQueueAttributesResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。