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


Java GetQueueAttributesRequest类代码示例

本文整理汇总了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;
}
 
开发者ID:mychaelstyle,项目名称:generic-queue,代码行数:17,代码来源:AwsSQS.java

示例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());

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

示例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));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:19,代码来源:SQSFailedEventSourceTest.java

示例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();
}
 
开发者ID:TimShi,项目名称:s3_video,代码行数:27,代码来源:AWSAdapter.java

示例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;
	}
}
 
开发者ID:yancykim,项目名称:support,代码行数:23,代码来源:SQS.java

示例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()));
					}
				});
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:21,代码来源:SqsExecutor.java

示例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")));
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:9,代码来源:MockSqsTest.java

示例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);
}
 
开发者ID:Mercateo,项目名称:sqs-utils,代码行数:12,代码来源:QueueFactory.java

示例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;
    }
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:16,代码来源:SQSFailedEventSource.java

示例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));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:13,代码来源:SQSFailedEventSourceTest.java

示例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));
}
 
开发者ID:zalando-nakadi,项目名称:paradox-nakadi-consumer,代码行数:11,代码来源:SQSFailedEventSourceTest.java

示例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;
}
 
开发者ID:smoketurner,项目名称:pipeline,代码行数:24,代码来源:AmazonSQSIterator.java

示例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"));
}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:13,代码来源:RemoteWorker.java

示例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"));
}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:8,代码来源:SQS.java

示例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"));
}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:8,代码来源:SQS.java


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