本文整理汇总了Java中com.amazonaws.services.sqs.model.GetQueueAttributesRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetQueueAttributesRequest类的具体用法?Java GetQueueAttributesRequest怎么用?Java GetQueueAttributesRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetQueueAttributesRequest类属于com.amazonaws.services.sqs.model包,在下文中一共展示了GetQueueAttributesRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: size
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
@Override
public long size() throws Exception {
// get all the attributes of the queue
List<String> attributeNames = new ArrayList<String>();
attributeNames.add("All");
// list the attributes of the queue we are interested in
GetQueueAttributesRequest request = new GetQueueAttributesRequest(queueUrl);
request.setAttributeNames(attributeNames);
Map<String, String> attributes = client.getQueueAttributes(request)
.getAttributes();
int messages = Integer.parseInt(attributes
.get("ApproximateNumberOfMessages"));
//int messagesNotVisible = Integer.parseInt(attributes
// .get("ApproximateNumberOfMessagesNotVisible"));
return (long) messages;
}
示例2: testGet
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的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.GetQueueAttributesRequest; //导入依赖的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: subscribeQueueToTopic
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
public String subscribeQueueToTopic(String snsTopicArn, String sqsQueueUrl){
Map<String, String> queueAttributes = sqsClient.getQueueAttributes(new GetQueueAttributesRequest(sqsQueueUrl)
.withAttributeNames(QueueAttributeName.QueueArn.toString())).getAttributes();
String sqsQueueArn = queueAttributes.get(QueueAttributeName.QueueArn.toString());
Policy policy = new Policy().withStatements(
new Statement(Effect.Allow)
.withId("topic-subscription-" + snsTopicArn)
.withPrincipals(Principal.AllUsers)
.withActions(SQSActions.SendMessage)
.withResources(new Resource(sqsQueueArn))
.withConditions(ConditionFactory.newSourceArnCondition(snsTopicArn)));
logger.debug("Policy: " + policy.toJson());
queueAttributes = new HashMap<String, String>();
queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson());
sqsClient.setQueueAttributes(new SetQueueAttributesRequest(sqsQueueUrl, queueAttributes));
SubscribeResult subscribeResult =
snsClient.subscribe(new SubscribeRequest()
.withEndpoint(sqsQueueArn)
.withProtocol("sqs")
.withTopicArn(snsTopicArn));
return subscribeResult.getSubscriptionArn();
}
示例5: getCount
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
public static int getCount(String name) {
try {
String queueUrl = getConnection().createQueue(
new CreateQueueRequest(name)).getQueueUrl();
List<String> attributeNames = new ArrayList<String>();
attributeNames.add("All");
// list the attributes of the queue we are interested in
GetQueueAttributesRequest request = new GetQueueAttributesRequest(queueUrl);
request.setAttributeNames(attributeNames);
Map<String, String> attributes = sqs.getQueueAttributes(request).getAttributes();
int messages = Integer.parseInt(attributes.get("ApproximateNumberOfMessages"));
//System.out.println("Messages in the queue: " + messages);
return messages;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
示例6: addPermissions
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的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()));
}
});
}
}
示例7: testNonInjectableMocks_shouldReturnNormal
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
@Test
public void testNonInjectableMocks_shouldReturnNormal() {
assertNotNull(sqs.changeMessageVisibilityBatch(new ChangeMessageVisibilityBatchRequest()));
assertNotNull(sqs.addPermission(new AddPermissionRequest().withActions("one").withAWSAccountIds("two","three").withLabel("four").withQueueUrl("five")));
assertNotNull(sqs.listDeadLetterSourceQueues(new ListDeadLetterSourceQueuesRequest().withQueueUrl("ten")));
assertNotNull(sqs.getQueueAttributes(new GetQueueAttributesRequest().withAttributeNames(ImmutableList.of("eleven")).withQueueUrl("twelve")));
assertNotNull(sqs.setQueueAttributes(new SetQueueAttributesRequest().withAttributes(ImmutableMap.of("thirteen","fourteen")).withQueueUrl("fifteen")));
}
示例8: get
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
public Queue get(@NonNull QueueName queueName) {
GetQueueUrlRequest urlRequest = new GetQueueUrlRequest().withQueueName(queueName.getId());
String queueUrl = amazonSQS.getQueueUrl(urlRequest).getQueueUrl();
GetQueueAttributesRequest attributesRequest = new GetQueueAttributesRequest(queueUrl,
Collections.singletonList("All"));
Map<String, String> attributes = amazonSQS.getQueueAttributes(attributesRequest)
.getAttributes();
return new Queue(queueName, queueUrl, attributes);
}
示例9: getSize
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的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;
}
}
示例10: testShouldReturnDefaultTotalNumberOfFailedEvents
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的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));
}
示例11: testShouldReturnDefaultTotalNumberOfFailedEventsWhenThereIsNoQueueAttributes
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的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));
}
示例12: getNumMessages
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的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;
}
示例13: getQueueSize
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
public static int getQueueSize(AmazonSQS sqs, String queueUrl){
HashMap<String, String> attributes;
Collection<String> attributeNames = new ArrayList<String>();
attributeNames.add("ApproximateNumberOfMessages");
GetQueueAttributesRequest getAttributesRequest = new GetQueueAttributesRequest(queueUrl)
.withAttributeNames(attributeNames);
attributes = (HashMap<String, String>) sqs.getQueueAttributes(getAttributesRequest).getAttributes();
return Integer.valueOf(attributes.get("ApproximateNumberOfMessages"));
}
示例14: getApproximateQueueSize
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
public int getApproximateQueueSize() {
Collection<String> attributeNames = new ArrayList<String>();
attributeNames.add("ApproximateNumberOfMessages");
GetQueueAttributesRequest queueAttributesRequest = new GetQueueAttributesRequest(queueURL).withAttributeNames(attributeNames);
Map<String, String> attributes = sqs.getQueueAttributes(queueAttributesRequest).getAttributes();
return Integer.valueOf(attributes.get("ApproximateNumberOfMessages"));
}
示例15: getApproximateNotVisibleMessageNum
import com.amazonaws.services.sqs.model.GetQueueAttributesRequest; //导入依赖的package包/类
public int getApproximateNotVisibleMessageNum() {
Collection<String> attributeNames = new ArrayList<String>();
attributeNames.add("ApproximateNumberOfMessagesNotVisible");
GetQueueAttributesRequest queueAttributesRequest = new GetQueueAttributesRequest(queueURL).withAttributeNames(attributeNames);
Map<String, String> attributes = sqs.getQueueAttributes(queueAttributesRequest).getAttributes();
return Integer.valueOf(attributes.get("ApproximateNumberOfMessagesNotVisible"));
}