本文整理汇总了Java中com.amazonaws.services.sqs.model.GetQueueUrlRequest类的典型用法代码示例。如果您正苦于以下问题:Java GetQueueUrlRequest类的具体用法?Java GetQueueUrlRequest怎么用?Java GetQueueUrlRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetQueueUrlRequest类属于com.amazonaws.services.sqs.model包,在下文中一共展示了GetQueueUrlRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGet
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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());
}
示例2: sendAndReceiveMessage
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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));
}
示例3: shouldCreateSqsQueueResource_withName
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
@Test
public void shouldCreateSqsQueueResource_withName() throws Exception {
// Given
final String name = randomString();
final String queueUrl = randomString();
final GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult().withQueueUrl(queueUrl);
final GetQueueUrlRequest expectedGetQueueUrlRequest = new GetQueueUrlRequest(name);
when(mockAmazonSqsClient.getQueueUrl(expectedGetQueueUrlRequest)).thenReturn(getQueueUrlResult);
final SqsQueueResource mockSqsQueueResource = mock(SqsQueueResource.class);
whenNew(SqsQueueResource.class).withArguments(name, queueUrl, mockAmazonSqsClient)
.thenReturn(mockSqsQueueResource);
// When
final SqsQueueResource result = factory.createSqsQueueResource(name);
// Then
assertSame(mockSqsQueueResource, result);
}
示例4: resolveDestination
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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);
}
}
}
示例5: testIsActive
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
@Test
public void testIsActive() throws Exception {
AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer();
AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly());
container.setAmazonSqs(mock);
container.setMessageHandler(mock(QueueMessageHandler.class));
container.afterPropertiesSet();
when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))).
thenReturn(new GetQueueUrlResult().withQueueUrl("http://testQueue.amazonaws.com"));
container.start();
assertTrue(container.isRunning());
container.stop();
assertFalse(container.isRunning());
//Container can still be active an restarted later (e.g. paused for a while)
assertTrue(container.isActive());
}
示例6: publish
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
@Override
public PublishResult publish(PublishRequest publishRequest) throws AmazonClientException {
String topicArn = publishRequest.getTopicArn();
if (!_subscriptionsForTopic.containsKey(topicArn)) {
throw new NotFoundException("no such topic " + topicArn);
}
List<Subscription> topicSubscriptions = FluentIterable.
from(_subscriptionsForTopic.get(topicArn)).
transform(Functions.forMap(_subscriptionsByArn)).
toList();
for (Subscription subscription : topicSubscriptions) {
String queueName = getLast(subscription.getEndpoint().split(":"));
String queueUrl = _sqsClient.
getQueueUrl(new GetQueueUrlRequest().withQueueName(queueName)).
getQueueUrl();
_sqsClient.sendMessage(new SendMessageRequest().
withQueueUrl(queueUrl).
withMessageBody(publishRequest.getMessage()));
}
return new PublishResult();
}
示例7: initalize
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
public void initalize(URI uri, Configuration conf) {
this.conf = conf;
String keyId = conf.get("fs."+uri.getScheme()+".awsAccessKeyId");
String keySecret = conf.get("fs."+uri.getScheme()+".awsSecretAccessKey");
//An override option for accessing across accounts
keyId = conf.get("fs."+uri.getScheme()+".override.awsAccessKeyId", keyId);
keySecret = conf.get("fs."+uri.getScheme()+".override.awsSecretAccessKey", keySecret);
sqs = new AmazonSQSClient(new BasicAWSCredentials(keyId, keySecret));
//SQS Consistency Queue
consistencyQueue = conf.get("fs"+uri.getScheme()+".alert.sqs.queue", consistencyQueue);
consistencyQueue = sqs.getQueueUrl(new GetQueueUrlRequest(consistencyQueue)).getQueueUrl();
//SQS Timeout Queue
timeoutQueue = conf.get("fs"+uri.getScheme()+".timeout.sqs.queue", timeoutQueue);
timeoutQueue = sqs.getQueueUrl(new GetQueueUrlRequest(timeoutQueue)).getQueueUrl();
}
示例8: initSqs
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
private void initSqs(String keyId, String keySecret) {
log.debug("Initializing SQS Client");
sqs = new AmazonSQSClient(new BasicAWSCredentials(keyId, keySecret));
//SQS Consistency Queue
consistencyQueue = conf.get("s3mper.alert.sqs.queue", consistencyQueue);
consistencyQueueUrl = sqs.getQueueUrl(new GetQueueUrlRequest(consistencyQueue)).getQueueUrl();
//SQS Timeout Queue
timeoutQueue = conf.get("s3mper.timeout.sqs.queue", timeoutQueue);
timeoutQueueUrl = sqs.getQueueUrl(new GetQueueUrlRequest(timeoutQueue)).getQueueUrl();
//SQS Notification Queue
notificationQueue = conf.get("s3mper.notification.sqs.queue", notificationQueue);
notificationQueueUrl = sqs.getQueueUrl(new GetQueueUrlRequest(notificationQueue)).getQueueUrl();
//Disable reporting (Testing purposes mostly)
reportingDisabled = conf.getBoolean("s3mper.reporting.disabled", reportingDisabled);
}
示例9: testCreateGetUrlListQueue_shouldCreateReturnUrlAndListQueue
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
@Test
public void testCreateGetUrlListQueue_shouldCreateReturnUrlAndListQueue() {
// create first queue
CreateQueueResult createdQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-earl-grey-queue"));
assertNotNull("verify that, on creation, queue url was returned",createdQueue.getQueueUrl());
// create other queues
CreateQueueResult secondTeaQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("tea-mate-queue"));
CreateQueueResult anotherQueue = sqs.createQueue(new CreateQueueRequest().withQueueName("coffee-queue"));
// get queue url
GetQueueUrlResult queueUrlResult = sqs.getQueueUrl(new GetQueueUrlRequest()
.withQueueName("tea-earl-grey-queue").withQueueOwnerAWSAccountId("some owner"));
assertNotNull("verify that, on fetch, queue url was returned", queueUrlResult.getQueueUrl());
// get all queues
ListQueuesResult allQueues = sqs.listQueues();
assertEquals("verify all queues are returned", 3, allQueues.getQueueUrls().size());
assertTrue("verify that all queues contain first queue", allQueues.getQueueUrls().contains(createdQueue.getQueueUrl()));
assertTrue("verify that all queues contain second tea queue", allQueues.getQueueUrls().contains(secondTeaQueue.getQueueUrl()));
assertTrue("verify that all queues contain coffee queue", allQueues.getQueueUrls().contains(anotherQueue.getQueueUrl()));
// get only queues that start with 'tea'
ListQueuesResult teaQueues = sqs.listQueues(new ListQueuesRequest("tea"));
assertEquals("verify only tea queues are returned", 2, teaQueues.getQueueUrls().size());
assertTrue("verify that tea queues contain first queue", teaQueues.getQueueUrls().contains(createdQueue.getQueueUrl()));
assertTrue("verify that tea queues contain second tea queue", teaQueues.getQueueUrls().contains(secondTeaQueue.getQueueUrl()));
assertNotNull("verify that delete queue returned ok", sqs.deleteQueue(new DeleteQueueRequest().withQueueUrl(queueUrlResult.getQueueUrl())));
assertFalse("verify that the queue was removed", sqs.listQueues().getQueueUrls().stream()
.anyMatch( queueUrl -> StringUtils.equals(queueUrl,queueUrlResult.getQueueUrl()) ));
// cleanup
getQueues().remove("tea-earl-grey-queue");
getQueues().remove("tea-mate-queue");
getQueues().remove("coffee-queue");
}
示例10: get
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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);
}
示例11: queryQueueUrl
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
private String queryQueueUrl(String queueName) {
try {
return _sqs.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl();
} catch (QueueDoesNotExistException e) {
// Create the queue
int visibilityTimeout = queueName.equals(_pendingScanRangeQueue) ?
DEFAULT_TASK_CLAIM_VISIBILITY_TIMEOUT : DEFAULT_TASK_COMPLETE_VISIBILITY_TIMEOUT;
return _sqs.createQueue(
new CreateQueueRequest(queueName)
.withAttributes(ImmutableMap.<String, String>of(
"VisibilityTimeout", String.valueOf(visibilityTimeout)))
).getQueueUrl();
}
}
示例12: getQueueUrl
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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));
}
示例13: deleteMessageSucceedsWithValidReceiptHandle
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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");
}
}
示例14: deleteMessageFailsWithInvalidReceiptHandle
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的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);
}
示例15: createSqsQueueResource
import com.amazonaws.services.sqs.model.GetQueueUrlRequest; //导入依赖的package包/类
@Override
public SqsQueueResource createSqsQueueResource(final String name) {
final String queueUrl = amazonSqsClient.getQueueUrl(new GetQueueUrlRequest(name)).getQueueUrl();
logger.info("Using existing SQS queue: " + name);
final SqsQueueResource sqsQueueResource = new SqsQueueResource(name, queueUrl, amazonSqsClient);
return sqsQueueResource;
}