本文整理汇总了Java中com.amazonaws.services.sqs.AmazonSQS类的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQS类的具体用法?Java AmazonSQS怎么用?Java AmazonSQS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonSQS类属于com.amazonaws.services.sqs包,在下文中一共展示了AmazonSQS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: changeMessageVisibilityMultiple
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
public static void changeMessageVisibilityMultiple(
String queue_url, int timeout)
{
AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
List<ChangeMessageVisibilityBatchRequestEntry> entries =
new ArrayList<ChangeMessageVisibilityBatchRequestEntry>();
entries.add(new ChangeMessageVisibilityBatchRequestEntry(
"unique_id_msg1",
sqs.receiveMessage(queue_url)
.getMessages()
.get(0)
.getReceiptHandle())
.withVisibilityTimeout(timeout));
entries.add(new ChangeMessageVisibilityBatchRequestEntry(
"unique_id_msg2",
sqs.receiveMessage(queue_url)
.getMessages()
.get(0)
.getReceiptHandle())
.withVisibilityTimeout(timeout + 200));
sqs.changeMessageVisibilityBatch(queue_url, entries);
}
示例2: getClient
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
/**
* Returns a client instance for AWS SQS.
* @return a client that talks to SQS
*/
public static AmazonSQS getClient() {
if (sqsClient != null) {
return sqsClient;
}
if (Config.IN_PRODUCTION) {
sqsClient = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY))).
withRegion(Config.AWS_REGION).build();
} else {
sqsClient = AmazonSQSClientBuilder.standard().
withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))).
withEndpointConfiguration(new EndpointConfiguration(LOCAL_ENDPOINT, "")).build();
}
Para.addDestroyListener(new DestroyListener() {
public void onDestroy() {
sqsClient.shutdown();
}
});
return sqsClient;
}
示例3: get
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
private static Flowable<SqsMessage> get(AmazonSQS sqs, String queueName, Optional<String> bucketName,
Optional<AmazonS3> s3, Service service, int waitTimeSeconds) {
return Flowable.defer(() -> {
final String queueUrl = sqs.getQueueUrl(queueName).getQueueUrl();
return Flowable.just(sqs.receiveMessage(request(queueName, waitTimeSeconds)) //
.getMessages() //
.stream() //
.map(m -> Sqs.getNextMessage(m, queueUrl, bucketName, s3, sqs, service)) //
.collect(Collectors.toList())) //
.concatWith(Flowable.defer(() -> Flowable.just(sqs.receiveMessage(request(queueName, 0)) //
.getMessages() //
.stream() //
.map(m -> Sqs.getNextMessage(m, queueUrl, bucketName, s3, sqs, service)) //
.collect(Collectors.toList()))) //
.repeat())
.takeWhile(list -> !list.isEmpty()) //
.flatMapIterable(x -> x) //
.filter(opt -> opt.isPresent()).map(opt -> opt.get());
});//
}
示例4: createSQSAsync
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Override
public AmazonSQS createSQSAsync(final SQSQueue queue) {
AWSCredentialsProvider credentials = queue.hasCredentials() ? queue.lookupAwsCredentials() : DefaultAWSCredentialsProviderChain.getInstance();
AmazonSQSAsyncClientBuilder sqsAsyncBuilder = createStandardAsyncClientBuilder(queue, credentials);
final QueueBufferConfig queueBufferConfig = this.getQueueBufferConfig(queue);
final AmazonSQSBufferedAsyncClient sqsBufferedAsync = new AmazonSQSBufferedAsyncClient(sqsAsyncBuilder.build(), queueBufferConfig);
return sqsBufferedAsync;
}
示例5: testSend
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
/**
* Tests the {@link BatchSQSMsgSender#send(org.apache.flume.Channel)} method. Tests the happy path scenario.
*
* @throws Exception
*/
@Test
public void testSend() throws Exception {
BatchSQSMsgSender sqsMsgSender =
new BatchSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey", 5, 10);
AmazonSQS mockSqs = Mockito.mock(AmazonSQS.class);
when(mockSqs.sendMessageBatch(any(SendMessageBatchRequest.class))).thenReturn(new SendMessageBatchResult());
sqsMsgSender.setAmazonSQS(mockSqs);
byte[] mockMsgPayload = {'A', 'b'};
Event mockEvent = Mockito.mock(Event.class);
when(mockEvent.getBody()).thenReturn(mockMsgPayload);
Channel mockChannel = Mockito.mock(Channel.class);
when(mockChannel.take()).thenReturn(mockEvent);
sqsMsgSender.send(mockChannel);
}
示例6: testSendFailureAmazonServiceException
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
/**
* Tests the {@link BatchSQSMsgSender#send(org.apache.flume.Channel)} method. Tests the failure scenario when AWS
* SQS API throws AmazonServiceException.
*
* @throws Exception
*/
@Test(expected = EventDeliveryException.class)
public void testSendFailureAmazonServiceException() throws Exception {
BatchSQSMsgSender sqsMsgSender =
new BatchSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey", 5, 10);
AmazonSQS mockSqs = Mockito.mock(AmazonSQS.class);
when(mockSqs.sendMessageBatch(any(SendMessageBatchRequest.class))).thenThrow(AmazonServiceException.class);
sqsMsgSender.setAmazonSQS(mockSqs);
byte[] mockMsgPayload = {'A', 'b'};
Event mockEvent = Mockito.mock(Event.class);
when(mockEvent.getBody()).thenReturn(mockMsgPayload);
Channel mockChannel = Mockito.mock(Channel.class);
when(mockChannel.take()).thenReturn(mockEvent);
sqsMsgSender.send(mockChannel);
}
示例7: testSendFailureAmazonClientException
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
/**
* Tests the {@link BatchSQSMsgSender#send(org.apache.flume.Channel)} method. Tests the failure scenario when AWS
* SQS API throws AmazonClientException.
*
* @throws Exception
*/
@Test(expected = EventDeliveryException.class)
public void testSendFailureAmazonClientException() throws Exception {
BatchSQSMsgSender sqsMsgSender =
new BatchSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey", 5, 10);
AmazonSQS mockSqs = Mockito.mock(AmazonSQS.class);
when(mockSqs.sendMessageBatch(any(SendMessageBatchRequest.class))).thenThrow(AmazonClientException.class);
sqsMsgSender.setAmazonSQS(mockSqs);
byte[] mockMsgPayload = {'A', 'b'};
Event mockEvent = Mockito.mock(Event.class);
when(mockEvent.getBody()).thenReturn(mockMsgPayload);
Channel mockChannel = Mockito.mock(Channel.class);
when(mockChannel.take()).thenReturn(mockEvent);
sqsMsgSender.send(mockChannel);
}
示例8: testSend
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Test
public void testSend() throws Exception {
BasicSQSMsgSender msgSender =
new BasicSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey");
Channel mockChannel = mock(Channel.class);
Event mockEvent = mock(Event.class);
when(mockEvent.getBody()).thenReturn("This is a test event message".getBytes());
when(mockChannel.take()).thenReturn(mockEvent);
AmazonSQS mockSqs = mock(AmazonSQS.class);
when(mockSqs.sendMessage(any(SendMessageRequest.class))).thenReturn(new SendMessageResult());
msgSender.setAmazonSQS(mockSqs);
int eventCount = msgSender.send(mockChannel);
assertEquals(1, eventCount);
}
示例9: testSendEventWithEmptyBody
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Test
public void testSendEventWithEmptyBody() throws Exception {
BasicSQSMsgSender msgSender =
new BasicSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey");
Channel mockChannel = mock(Channel.class);
Event mockEvent = mock(Event.class);
when(mockEvent.getBody()).thenReturn("".getBytes());
when(mockChannel.take()).thenReturn(mockEvent);
AmazonSQS mockSqs = mock(AmazonSQS.class);
when(mockSqs.sendMessage(any(SendMessageRequest.class))).thenReturn(new SendMessageResult());
msgSender.setAmazonSQS(mockSqs);
int eventCount = msgSender.send(mockChannel);
assertEquals(0, eventCount);
}
示例10: testSendFailureAmazonServiceException
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testSendFailureAmazonServiceException() throws Exception {
BasicSQSMsgSender msgSender =
new BasicSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey");
Channel mockChannel = mock(Channel.class);
Event mockEvent = mock(Event.class);
when(mockEvent.getBody()).thenReturn("This is a test event message".getBytes());
when(mockChannel.take()).thenReturn(mockEvent);
AmazonSQS mockSqs = mock(AmazonSQS.class);
when(mockSqs.sendMessage(any(SendMessageRequest.class)))
.thenThrow(new AmazonServiceException("Mock AmazonServiceException"));
msgSender.setAmazonSQS(mockSqs);
msgSender.send(mockChannel);
}
示例11: testSendFailureAmazonClientException
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testSendFailureAmazonClientException() throws Exception {
BasicSQSMsgSender msgSender =
new BasicSQSMsgSender("https://some-fake/url", "us-east-1", "someAwsAccessKey", "someAwsSecretKey");
Channel mockChannel = mock(Channel.class);
Event mockEvent = mock(Event.class);
when(mockEvent.getBody()).thenReturn("This is a test event message".getBytes());
when(mockChannel.take()).thenReturn(mockEvent);
AmazonSQS mockSqs = mock(AmazonSQS.class);
when(mockSqs.sendMessage(any(SendMessageRequest.class)))
.thenThrow(new AmazonClientException("Mock AmazonClientException"));
msgSender.setAmazonSQS(mockSqs);
msgSender.send(mockChannel);
}
示例12: pollMessages
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
private void pollMessages(AmazonSQS sqs) {
log.info("Polling messages");
while (true) {
List<Message> messages = sqs.receiveMessage(QUEUE_URL).getMessages();
messages.forEach(m -> {
log.info("Message Received: " + m.getBody());
System.out.println(m.getBody());
DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(QUEUE_URL, m.getReceiptHandle());
sqs.deleteMessage(deleteMessageRequest);
});
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
}
}
示例13: testGetAmazonSQSClientCacheHitMiss
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Test
public void testGetAmazonSQSClientCacheHitMiss()
{
// Create an AWS parameters DTO that contains proxy information.
AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Get an Amazon SQS client.
AmazonSQS amazonSQS = awsClientFactory.getAmazonSQSClient(awsParamsDto);
// Confirm a cache hit.
assertEquals(amazonSQS,
awsClientFactory.getAmazonSQSClient(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
// Confirm a cache miss due to http proxy information.
assertNotEquals(amazonSQS, awsClientFactory
.getAmazonSQSClient(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST_2, HTTP_PROXY_PORT_2)));
// Clear the cache.
cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();
// Confirm a cache miss due to cleared cache.
assertNotEquals(amazonSQS, awsClientFactory.getAmazonSQSClient(awsParamsDto));
}
示例14: sendMessage
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的package包/类
@Override
public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS)
{
// Throw a throttling exception for a specific queue name for testing purposes.
if (queueName.equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION))
{
AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception");
throttlingException.setErrorCode("ThrottlingException");
throw throttlingException;
}
// Throw an illegal state exception for a specific queue name for testing purposes.
if (queueName.equals(MOCK_SQS_QUEUE_NOT_FOUND_NAME))
{
throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName));
}
// Nothing else to do in the normal case since our unit tests aren't reading messages once they have been published.
return new SendMessageResult().withMessageId(AbstractDaoTest.MESSAGE_ID);
}
示例15: shouldGetCorrectQueueUrl
import com.amazonaws.services.sqs.AmazonSQS; //导入依赖的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);
}