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


Java GetQueueUrlResult.getQueueUrl方法代码示例

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


在下文中一共展示了GetQueueUrlResult.getQueueUrl方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUrlForQueue

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
/**
 * Retrieves queue url for the given queue name. If the queue does not exist, tries to create it.
 *
 * @param queueName the queue name to get url for
 * @return an optional String representing the queue url
 */
Optional<String> getUrlForQueue(String queueName) {
    Optional<String> queueUrl = Optional.empty();
    try {
        GetQueueUrlResult queueUrlResult = sqs.getQueueUrl(queueName);
        if (queueUrlResult.getQueueUrl() != null) {
            queueUrl = Optional.of(queueUrlResult.getQueueUrl());
        }
    } catch (QueueDoesNotExistException e) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("Queue " + queueName + " does not exist, try to create it",e);
        }
        CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
        try {
            queueUrl = Optional.of(sqs.createQueue(createQueueRequest).getQueueUrl());
        } catch (AmazonClientException e2) {
            LOGGER.error("Could not create queue " + queueName + ", bundle won't work",e2);
        }
    }

    return queueUrl;
}
 
开发者ID:sjarrin,项目名称:dropwizard-sqs-bundle,代码行数:28,代码来源:SqsBundle.java

示例2: initQueue

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
private void initQueue() {
	this.sqs = new AmazonSQSClient(); // Do we need to use new
										// ClientConfiguration().withMaxConnections(256)
										// ?
	this.sqs.configureRegion(region);
	try {
		// Check to see if queue exists
		GetQueueUrlResult queueUrlResult = this.sqs.getQueueUrl(getSqsQueueName());
		this.queueUrl = queueUrlResult.getQueueUrl();
	} catch (QueueDoesNotExistException queueDoesNotExist) {
		// Queue does not exist, need to create one
		CreateQueueRequest createQueueRequest = new CreateQueueRequest();
		createQueueRequest.setQueueName(getSqsQueueName());
		createQueueRequest.addAttributesEntry("VisibilityTimeout", "" + getVisibilityTimeout());
		CreateQueueResult createQueueResult = this.sqs.createQueue(createQueueRequest);
		this.queueUrl = createQueueResult.getQueueUrl();
	}
}
 
开发者ID:olegdulin,项目名称:sqs-retryqueue,代码行数:19,代码来源:SQSRetryQueue.java

示例3: sendAndReceiveMessage

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test
public void sendAndReceiveMessage() {
  final String queueName = "bizo";
  final String messageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final SendMessageRequest sendMessageRequest =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
  sqs.sendMessage(sendMessageRequest);

  final int maxNumberOfMessages = 10;

  final ReceiveMessageRequest receiveMessageRequest =
    new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);
  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();

  assertThat(messages.size(), equalTo(1));
  assertThat(messages.get(0).getBody(), equalTo(messageBody));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:27,代码来源:AmazonSQSStubTest.java

示例4: run

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void run() {	
	//Get queue url	
       GetQueueUrlResult urlResult = sqs.getQueueUrl(responseQName);
       String QueueUrl = urlResult.getQueueUrl();
       JSONObject result = new JSONObject();
       
       try {
       	Thread.sleep(sleepLength);
       	
       	result.put("task_id", task_id);
       	result.put("result", "0");
       	
       	sqs.sendMessage(new SendMessageRequest(QueueUrl, result.toString()));
       	//System.out.println(Thread.currentThread().getName()+" sleep done!");
       	
       } catch (Exception e) {
       	result.put("task_id", task_id);
       	result.put("result", "1");
       	sqs.sendMessage(new SendMessageRequest(QueueUrl, result.toString()));
       	
       }
}
 
开发者ID:cs553-cloud-computing,项目名称:amazon-cloudengine,代码行数:25,代码来源:WorkerThread.java

示例5: getAndSetQueueUrl

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
/**
 * Get a queue url from a queue name
 * @param queueName
 * @return queueUrl - For the specified queue name
 */
private synchronized String getAndSetQueueUrl(final String queueName) throws QueueDoesNotExistException{
	try{

		final String url = queueUrlMap.get(queueName); 
		if(url != null){
			return url;
		}else{
			final GetQueueUrlResult result = this.sqs.getQueueUrl(queueName);
			if(result != null && !Strings.isNullOrEmpty(result.getQueueUrl())){
					queueUrlMap.put(queueName, result.getQueueUrl());	
					return result.getQueueUrl();
			}				
		}
	}catch(QueueDoesNotExistException qne){
		throw qne;
	}catch(Exception ex){
		throw new RuntimeException(ex.getMessage(), ex);
	}
	return null;
}
 
开发者ID:shagwood,项目名称:micro-genie,代码行数:26,代码来源:SqsQueueAdmin.java

示例6: resolveDestination

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Override
public String resolveDestination(String name) throws DestinationResolutionException {
    String queueName = name;

    if (this.resourceIdResolver != null) {
        queueName = this.resourceIdResolver.resolveToPhysicalResourceId(name);
    }

    if (isValidQueueUrl(queueName)) {
        return queueName;
    }

    if (this.autoCreate) {
        //Auto-create is fine to be called even if the queue exists.
        CreateQueueResult createQueueResult = this.amazonSqs.createQueue(new CreateQueueRequest(queueName));
        return createQueueResult.getQueueUrl();
    } else {
        try {
            GetQueueUrlResult getQueueUrlResult = this.amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueName));
            return getQueueUrlResult.getQueueUrl();
        } catch (QueueDoesNotExistException e) {
            throw new DestinationResolutionException(e.getMessage(), e);
        }
    }
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:26,代码来源:DynamicQueueUrlDestinationResolver.java

示例7: poll

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Override
public void poll(long waitInterval ) {
	Properties properties = new Properties();
	
	String access_key_id = getProperty("AccessKeyId");
       String secret_access_key = getProperty("SecretAccessKey");
       BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);
	
       AmazonSQS sqs = new AmazonSQSClient(credentials);
       
       // Region selection
       Region region = Region.getRegion(Regions.fromName(getProperty("region")));
       sqs.setRegion(region);
       
       GetQueueUrlResult queueUrl = sqs.getQueueUrl(getProperty("Queue"));
       
       ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl.getQueueUrl());
       List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
       
       String outputMessage = "";
       // if there are messages then do the processing
       if(messages.size() > 0){
       	
       	//append the message properties to the localenv tree
       	for (Message message : messages) {
               properties.setProperty("MessageId", message.getMessageId());
               properties.setProperty("ReceiptHandle", message.getReceiptHandle());
               properties.setProperty("MD5OfBody", message.getMD5OfBody());
               // get the message body to a string
               outputMessage = message.getBody();
           }
       	properties.setProperty("queueUrl", queueUrl.getQueueUrl());
           // delete the message from the queue
           String messageReceiptHandle = messages.get(0).getReceiptHandle();
           sqs.deleteMessage(new DeleteMessageRequest(queueUrl.getQueueUrl(), messageReceiptHandle));
           ConnectorCallback callback = getCallback();
   		callback.processInboundData(outputMessage.getBytes(), properties);
       }
}
 
开发者ID:ot4i,项目名称:amazon-sqs-connector,代码行数:40,代码来源:AmazonSQSInputConnector.java

示例8: getQueueUrl

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test
public void getQueueUrl() {
  final String queueName = "bizo";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();
  assertThat(queueUrl, containsString(queueName));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:13,代码来源:AmazonSQSStubTest.java

示例9: deleteMessageSucceedsWithValidReceiptHandle

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test
public void deleteMessageSucceedsWithValidReceiptHandle() {
  final String queueName = "bizo";
  final String messageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final SendMessageRequest sendMessageRequest =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
  sqs.sendMessage(sendMessageRequest);

  final int maxNumberOfMessages = 10;

  final ReceiveMessageRequest receiveMessageRequest =
    new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);
  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();
  assertThat(messages.size(), equalTo(1));

  final String receiptHandle = messages.get(0).getReceiptHandle();
  final DeleteMessageRequest deleteMessageRequest =
    new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(receiptHandle);

  try {
    sqs.deleteMessage(deleteMessageRequest);
  } catch (ReceiptHandleIsInvalidException e) {
    fail("ReceiptHandleIsInvalidException was thrown");
  }
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:35,代码来源:AmazonSQSStubTest.java

示例10: deleteMessageFailsWithInvalidReceiptHandle

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test(expected = ReceiptHandleIsInvalidException.class)
public void deleteMessageFailsWithInvalidReceiptHandle() {
  final String queueName = "bizo";
  final String messageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final SendMessageRequest sendMessageRequest =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
  sqs.sendMessage(sendMessageRequest);

  final ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueUrl);
  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();
  assertThat(messages.size(), equalTo(1));

  final String receiptHandle = "bizo";
  final DeleteMessageRequest deleteMessageRequest =
    new DeleteMessageRequest().withQueueUrl(queueUrl).withReceiptHandle(receiptHandle);

  sqs.deleteMessage(deleteMessageRequest);
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:28,代码来源:AmazonSQSStubTest.java

示例11: doStart

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
    client = getConfiguration().getAmazonSQSClient() != null
        ? getConfiguration().getAmazonSQSClient() : getClient();
        
    // Override the endpoint location
    if (ObjectHelper.isNotEmpty(getConfiguration().getAmazonSQSEndpoint())) {
        client.setEndpoint(getConfiguration().getAmazonSQSEndpoint());
    }
    
    // check the setting the headerFilterStrategy
    if (headerFilterStrategy == null) {
        headerFilterStrategy = new SqsHeaderFilterStrategy();
    }

    // If both region and Account ID is provided the queue URL can be built manually.
    // This allows accessing queues where you don't have permission to list queues or query queues
    if (configuration.getRegion() != null && configuration.getQueueOwnerAWSAccountId() != null) {
        queueUrl = "https://sqs." + configuration.getRegion() + ".amazonaws.com/"
            +  configuration.getQueueOwnerAWSAccountId() + "/" + configuration.getQueueName();
    } else if (configuration.getQueueOwnerAWSAccountId() != null) {
        GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest();
        getQueueUrlRequest.setQueueName(configuration.getQueueName());
        getQueueUrlRequest.setQueueOwnerAWSAccountId(configuration.getQueueOwnerAWSAccountId());
        GetQueueUrlResult getQueueUrlResult = client.getQueueUrl(getQueueUrlRequest);
        queueUrl = getQueueUrlResult.getQueueUrl();
    } else {
        // check whether the queue already exists
        ListQueuesResult listQueuesResult = client.listQueues();
        for (String url : listQueuesResult.getQueueUrls()) {
            if (url.endsWith("/" + configuration.getQueueName())) {
                queueUrl = url;
                LOG.trace("Queue available at '{}'.", queueUrl);
                break;
            }
        }
    }

    if (queueUrl == null) {
        createQueue(client);
    } else {
        updateQueueAttributes(client);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:45,代码来源:SqsEndpoint.java

示例12: receiveMessageReturnsMaxNumberOfMessages

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test
public void receiveMessageReturnsMaxNumberOfMessages() {
  final String queueName = "bizo";
  final String baseMessageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final List<String> sentMessageBodies = new ArrayList<String>();
  final int numMessages = 7;
  for (int i = 0; i < numMessages; i++) {
    sentMessageBodies.add(baseMessageBody + " " + i);
  }

  for (String messageBody : sentMessageBodies) {
    final SendMessageRequest sendMessageRequest =
      new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody(messageBody);
    sqs.sendMessage(sendMessageRequest);
  }

  final int maxNumberOfMessages = 5;

  final List<String> expectedMessageBodies = sentMessageBodies.subList(0, maxNumberOfMessages);

  final ReceiveMessageRequest receiveMessageRequest =
    new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);

  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();
  assertThat(messages.size(), equalTo(maxNumberOfMessages));

  final List<String> actualMessageBodies = new ArrayList<String>();
  for (Message m : messages) {
    actualMessageBodies.add(m.getBody());
  }
  assertThat(actualMessageBodies, equalTo(expectedMessageBodies));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:42,代码来源:AmazonSQSStubTest.java

示例13: receiveMessageOnlyReturnsRequestedAttributes

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test
public void receiveMessageOnlyReturnsRequestedAttributes() {
  final String queueName = "bizo";
  final String messageBody = "hi everybody";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final Map<String, MessageAttributeValue> messageAttributes = new HashMap<String, MessageAttributeValue>();
  messageAttributes.put("key A", new MessageAttributeValue().withDataType("String").withStringValue("value A"));
  messageAttributes.put("key B", new MessageAttributeValue().withDataType("String").withStringValue("value B"));
  messageAttributes.put("key C", new MessageAttributeValue().withDataType("String").withStringValue("value C"));
  messageAttributes.put("key D", new MessageAttributeValue().withDataType("String").withStringValue("value D"));
  messageAttributes.put("key E", new MessageAttributeValue().withDataType("String").withStringValue("value E"));
  final SendMessageRequest sendMessageRequest =
    new SendMessageRequest()
      .withQueueUrl(queueUrl)
      .withMessageBody(messageBody)
      .withMessageAttributes(messageAttributes);
  sqs.sendMessage(sendMessageRequest);

  final int maxNumberOfMessages = 10;

  final ReceiveMessageRequest receiveMessageRequest =
    new ReceiveMessageRequest()
      .withQueueUrl(queueUrl)
      .withMaxNumberOfMessages(maxNumberOfMessages)
      .withMessageAttributeNames("key B", "key E");
  final ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest);
  final List<Message> messages = receiveMessageResult.getMessages();

  assertThat(messages.size(), equalTo(1));

  Message m = messages.get(0);
  assertThat(m.getBody(), equalTo(messageBody));

  final Map<String, MessageAttributeValue> expectedMessageAttributes =
    new HashMap<String, MessageAttributeValue>(messageAttributes);
  expectedMessageAttributes.keySet().retainAll(Arrays.asList("key B", "key E"));
  assertThat(m.getMessageAttributes(), equalTo(expectedMessageAttributes));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:46,代码来源:AmazonSQSStubTest.java

示例14: returnMessage

import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入方法依赖的package包/类
@Test
public void returnMessage() {
  final String queueName = "bizo";

  final CreateQueueRequest createQueueRequest = new CreateQueueRequest().withQueueName(queueName);
  sqs.createQueue(createQueueRequest);

  final GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest().withQueueName(queueName);
  final GetQueueUrlResult getQueueUrlResult = sqs.getQueueUrl(getQueueUrlRequest);
  final String queueUrl = getQueueUrlResult.getQueueUrl();

  final SendMessageRequest sendMessageRequest1 =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 1");
  sqs.sendMessage(sendMessageRequest1);

  final SendMessageRequest sendMessageRequest2 =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 2");
  sqs.sendMessage(sendMessageRequest2);

  final SendMessageRequest sendMessageRequest3 =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 3");
  sqs.sendMessage(sendMessageRequest3);

  final int maxNumberOfMessages = 10;

  final ReceiveMessageRequest receiveMessageRequest1 =
    new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);
  final ReceiveMessageResult receiveMessageResult1 = sqs.receiveMessage(receiveMessageRequest1);
  final List<Message> messages1 = receiveMessageResult1.getMessages();

  final SendMessageRequest sendMessageRequest4 =
    new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hi everybody 4");
  sqs.sendMessage(sendMessageRequest4);

  // "hi everybody 2" should be at the top of the queue after being returned.
  sqs.returnMessage(queueUrl, messages1.get(1));

  final ReceiveMessageRequest receiveMessageRequest2 =
    new ReceiveMessageRequest().withQueueUrl(queueUrl).withMaxNumberOfMessages(maxNumberOfMessages);
  final ReceiveMessageResult receiveMessageResult2 = sqs.receiveMessage(receiveMessageRequest2);
  final List<Message> messages2 = receiveMessageResult2.getMessages();

  final List<String> expectedMessageBodies =
    Arrays.asList(sendMessageRequest2.getMessageBody(), sendMessageRequest4.getMessageBody());

  final List<String> actualMessageBodies = new ArrayList<String>();
  for (Message m : messages2) {
    actualMessageBodies.add(m.getBody());
  }

  assertThat(actualMessageBodies, equalTo(expectedMessageBodies));
}
 
开发者ID:bizo,项目名称:aws-java-sdk-stubs,代码行数:53,代码来源:AmazonSQSStubTest.java


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