本文整理汇总了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));
}
}
示例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());
}
示例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));
}
示例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()));
}
});
}
}
示例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)
));
}
示例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;
}
}
示例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;
}
}
示例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));
}
示例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));
}
示例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;
}
示例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());
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}