本文整理汇总了Java中com.amazonaws.services.sqs.model.GetQueueUrlResult类的典型用法代码示例。如果您正苦于以下问题:Java GetQueueUrlResult类的具体用法?Java GetQueueUrlResult怎么用?Java GetQueueUrlResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetQueueUrlResult类属于com.amazonaws.services.sqs.model包,在下文中一共展示了GetQueueUrlResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessage() {
final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
final String queueName = "queue";
Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
Sqs.queueName(queueName) //
.sqsFactory(() -> sqs) //
.messages() //
.map(m -> m.message()) //
.doOnError(Throwable::printStackTrace) //
.take(1) //
.test() //
.awaitDone(10, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue("body1");
final InOrder inorder = Mockito.inOrder(sqs);
inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
inorder.verify(sqs, Mockito.times(1)).shutdown();
inorder.verifyNoMoreInteractions();
}
示例3: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure() {
final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
final String queueName = "queue";
Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
Sqs.queueName(queueName) //
.sqsFactory(() -> sqs) //
.messages() //
.map(m -> m.message()) //
.doOnError(Throwable::printStackTrace) //
.test(0) //
.requestMore(1) //
.assertValue("body1")//
.assertNotComplete() //
.cancel();
final InOrder inorder = Mockito.inOrder(sqs);
inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
inorder.verify(sqs, Mockito.times(1)).shutdown();
inorder.verifyNoMoreInteractions();
}
示例4: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages() {
final AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
final String queueName = "queue";
Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any())).thenReturn(new ReceiveMessageResult())
.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1"),
new Message().withBody("body2")));
Sqs.queueName(queueName) //
.sqsFactory(() -> sqs) //
.messages() //
.map(m -> m.message()) //
.doOnError(Throwable::printStackTrace) //
.take(2) //
.test() //
.awaitDone(10, TimeUnit.SECONDS) //
.assertComplete() //
.assertValues("body1", "body2");
final InOrder inorder = Mockito.inOrder(sqs);
inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
inorder.verify(sqs, Mockito.times(2)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
inorder.verify(sqs, Mockito.times(1)).shutdown();
inorder.verifyNoMoreInteractions();
}
示例5: testGet
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的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());
}
示例6: run
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Override
public void run() {
rxSqsClient.getQueueUrlAsync(queueName)
.last()
.map(GetQueueUrlResult::getQueueUrl)
.subscribe(url -> {
rxSqsClient.receiveMessageAsync(url)
.subscribeOn(Schedulers.io())
.subscribe(message -> {
System.out.println(name + ": " + message.getBody() + "[" + message.getMessageId() + "]");
rxSqsClient.deleteMessageAsync(url, message.getReceiptHandle())
.toBlocking()
.subscribe(result -> {
System.out.println("Acknowledged Message " + message.getMessageId());
});
}, Throwable::printStackTrace);
});
}
示例7: testShouldGetFailedResponseAfterSendingTheEvent
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test
public void testShouldGetFailedResponseAfterSendingTheEvent() {
final GetQueueUrlResult getQueueUrlResult = new GetQueueUrlResult();
getQueueUrlResult.setQueueUrl(randomAlphabetic(10));
final SendMessageResult sendMessageResult = new SendMessageResult();
final SdkHttpMetadata responseMetadata = mock(SdkHttpMetadata.class);
when(responseMetadata.getHttpStatusCode()).thenReturn(400);
sendMessageResult.setSdkHttpMetadata(responseMetadata);
when(amazonSQS.sendMessage(any(SendMessageRequest.class))).thenThrow(new RuntimeException("expected"));
assertThatThrownBy(() ->
sqsErrorHandler.onError(randomAlphabetic(10), new RuntimeException(),
EventTypePartition.of(EventType.of(randomAlphabetic(10)),
randomAlphabetic(1)), randomNumeric(10), randomAlphabetic(50)))
.isInstanceOf(RuntimeException.class).hasMessageContaining("expected");
}
示例8: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessage() {
AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
String queueName = "queue";
Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
Sqs.queueName(queueName) //
.sqsFactory(() -> sqs) //
.messages() //
.map(m -> m.message()) //
.doOnError(Throwable::printStackTrace) //
.take(1) //
.to(test()) //
.awaitTerminalEvent() //
.assertCompleted() //
.assertValue("body1");
InOrder inorder = Mockito.inOrder(sqs);
inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
inorder.verify(sqs, Mockito.times(1)).shutdown();
inorder.verifyNoMoreInteractions();
}
示例9: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure() {
AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
String queueName = "queue";
Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any()))
.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1")));
Sqs.queueName(queueName) //
.sqsFactory(() -> sqs) //
.messages() //
.map(m -> m.message()) //
.doOnError(Throwable::printStackTrace) //
.to(testWithRequest(0)) //
.requestMore(1) //
.assertValue("body1")//
.assertNotCompleted() //
.unsubscribe();
InOrder inorder = Mockito.inOrder(sqs);
inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
inorder.verify(sqs, Mockito.times(1)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
inorder.verify(sqs, Mockito.times(1)).shutdown();
inorder.verifyNoMoreInteractions();
}
示例10: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test(timeout = 5000)
public void testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages() {
AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
String queueName = "queue";
Mockito.when(sqs.getQueueUrl(queueName)).thenAnswer(x -> new GetQueueUrlResult().withQueueUrl(queueName));
Mockito.when(sqs.receiveMessage(Mockito.<ReceiveMessageRequest>any())).thenReturn(new ReceiveMessageResult())
.thenReturn(new ReceiveMessageResult().withMessages(new Message().withBody("body1"),
new Message().withBody("body2")));
Sqs.queueName(queueName) //
.sqsFactory(() -> sqs) //
.messages() //
.map(m -> m.message()) //
.doOnError(Throwable::printStackTrace) //
.take(2) //
.to(test()) //
.awaitTerminalEvent() //
.assertCompleted() //
.assertValues("body1", "body2");
InOrder inorder = Mockito.inOrder(sqs);
inorder.verify(sqs, Mockito.atLeastOnce()).getQueueUrl(queueName);
inorder.verify(sqs, Mockito.times(2)).receiveMessage(Mockito.<ReceiveMessageRequest>any());
inorder.verify(sqs, Mockito.times(1)).shutdown();
inorder.verifyNoMoreInteractions();
}
示例11: shouldGetCorrectQueueUrl
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test
public void shouldGetCorrectQueueUrl() throws Exception {
//GIVEN
AmazonSQS sqs = mock(AmazonSQS.class);
field("sqs").ofType(AmazonSQS.class).in(bundle).set(sqs);
String queueUrl = "https://eu-central-1/queue.amazonaws.com/123456/test-queue";
when(sqs.getQueueUrl("test-queue")).thenReturn(new GetQueueUrlResult()
.withQueueUrl(queueUrl));
//WHEN
Optional<String> urlForQueue = bundle.getUrlForQueue("test-queue");
//THEN
assertThat(urlForQueue.isPresent()).isTrue();
assertThat(urlForQueue.get()).isEqualTo(queueUrl);
}
示例12: shouldCorrectlyCreateSenderIfQueueExists
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Test
public void shouldCorrectlyCreateSenderIfQueueExists() throws Exception, CannotCreateSenderException {
//GIVEN
AmazonSQS sqs = mock(AmazonSQS.class);
field("sqs").ofType(AmazonSQS.class).in(bundle).set(sqs);
String queueUrl = "https://eu-central-1/queue.amazonaws.com/123456/test-queue";
when(sqs.getQueueUrl("test-queue")).thenReturn(new GetQueueUrlResult()
.withQueueUrl(queueUrl));
//WHEN
SqsSender sender = bundle.createSender("test-queue");
//THEN
assertThat(sender).isNotNull();
}
示例13: 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();
}
}
示例14: send
import com.amazonaws.services.sqs.model.GetQueueUrlResult; //导入依赖的package包/类
@Override
public Properties send(Properties properties, Object message)
throws ConnectorException {
String access_key_id = properties.getProperty("AccessKeyId");
String secret_access_key = properties.getProperty("SecretAccessKey");
BasicAWSCredentials credentials = new BasicAWSCredentials(access_key_id, secret_access_key);
AmazonSQS sqs = new AmazonSQSClient(credentials);
//System.out.println(properties.getProperty("region"));
// Region selection
Region region = Region.getRegion(Regions.fromName(properties.getProperty("region")));
sqs.setRegion(region);
GetQueueUrlResult queueUrl = sqs.getQueueUrl(properties.getProperty("Queue"));
String messageStr = new String((byte[])message);
sqs.sendMessage(new SendMessageRequest(queueUrl.getQueueUrl(), messageStr));
return properties;
}
示例15: 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));
}