本文整理汇总了Java中com.amazonaws.services.sqs.AmazonSQSClient类的典型用法代码示例。如果您正苦于以下问题:Java AmazonSQSClient类的具体用法?Java AmazonSQSClient怎么用?Java AmazonSQSClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AmazonSQSClient类属于com.amazonaws.services.sqs包,在下文中一共展示了AmazonSQSClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shutdownOfSqsAndS3FactoryCreatedClientsOccursWhenS3DeleteObjectFails
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
@Test
public void shutdownOfSqsAndS3FactoryCreatedClientsOccursWhenS3DeleteObjectFails() {
AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
String s3Id = "123";
SqsMessage m = new SqsMessage(RECEIPT_HANDLE, new byte[] {}, 1000, Optional.of(s3Id),
new SqsMessage.Service(Optional.of(() -> s3), () -> sqs, Optional.of(s3), sqs,
QUEUE, Optional.of(BUCKET)));
Mockito.when(sqs.deleteMessage(QUEUE, RECEIPT_HANDLE))
.thenReturn(new DeleteMessageResult());
Mockito.doThrow(new RuntimeException()).when(s3).deleteObject(BUCKET, s3Id);
try {
m.deleteMessage(Client.FROM_FACTORY);
Assert.fail();
} catch (RuntimeException e) {
// do nothing
}
InOrder inorder = Mockito.inOrder(sqs, s3);
inorder.verify(s3, Mockito.times(1)).deleteObject(BUCKET, s3Id);
inorder.verify(s3, Mockito.times(1)).shutdown();
inorder.verify(sqs, Mockito.times(1)).shutdown();
Mockito.verifyNoMoreInteractions(sqs, s3);
}
示例2: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的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.AmazonSQSClient; //导入依赖的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.AmazonSQSClient; //导入依赖的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: Processor
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
public Processor(ProcessorConfig config) {
ProfileCredentialsProvider creds = new ProfileCredentialsProvider(config.profile());
creds.getCredentials(); // credible credential criteria
if (config.disableCerts())
System.setProperty("com.amazonaws.sdk.disableCertChecking", "true");
// Rekognition init
rek = new AmazonRekognitionClient(creds);
if (config.endpointOverride())
rek.setEndpoint(config.endpoint());
minConfidence = Integer.parseInt(config.confidence());
// The SQS queue to find jobs on
sqs = new AmazonSQSClient(creds);
queueUrl = sqs.createQueue(config.queue()).getQueueUrl();
// Processors
if (config.wantCloudSearch())
processors.add(new CloudSearchIndexer(creds, config.cloudSearch()));
if (config.wantDynamo())
processors.add(new DynamoWriter(creds, config.dynamo()));
if (config.wantTags3())
processors.add(new S3ObjectTagger(creds, config.tagPrefix()));
// Executor Service
int maxWorkers = Integer.parseInt(config.concurrency());
executor = new ThreadPoolExecutor(
1, maxWorkers, 30, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(maxWorkers * 2, false),
new CallerRunsPolicy() // prevents backing up too many jobs
);
maxImagesToProcess = Long.parseLong(config.max());
}
示例6: Service
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
Service(Optional<Func0<AmazonS3Client>> s3Factory, Func0<AmazonSQSClient> sqsFactory,
Optional<AmazonS3Client> s3, AmazonSQSClient sqs, String queueName,
Optional<String> bucketName) {
Preconditions.checkNotNull(s3Factory);
Preconditions.checkNotNull(sqsFactory);
Preconditions.checkNotNull(s3);
Preconditions.checkNotNull(sqs);
Preconditions.checkNotNull(queueName);
Preconditions.checkNotNull(bucketName);
this.s3Factory = s3Factory;
this.sqsFactory = sqsFactory;
this.s3 = s3;
this.sqs = sqs;
this.queueName = queueName;
this.bucketName = bucketName;
}
示例7: get
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
private static Observable<SqsMessage> get(AmazonSQSClient sqs, String queueName,
Optional<String> bucketName, Optional<AmazonS3Client> s3, Service service,
int waitTimeSeconds) {
return Observable.defer(() -> {
String queueUrl = sqs.getQueueUrl(queueName).getQueueUrl();
return Observable
.just(sqs.receiveMessage(request(queueName, waitTimeSeconds)) //
.getMessages() //
.stream() //
.map(m -> Sqs.getNextMessage(m, queueUrl, bucketName, s3, sqs, service)) //
.collect(Collectors.toList())) //
.concatWith(Observable
.defer(() -> Observable.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(Functions.identity()) //
.filter(opt -> opt.isPresent()).map(opt -> opt.get());
});//
}
示例8: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的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.AmazonSQSClient; //导入依赖的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.AmazonSQSClient; //导入依赖的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: ensureIfSendToSqsFailsThatS3ObjectIsDeleted
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void ensureIfSendToSqsFailsThatS3ObjectIsDeleted() {
AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
Mockito.when(sqs.sendMessage(Mockito.anyString(), Mockito.anyString())).thenThrow(RuntimeException.class);
try {
Sqs.sendToQueueUsingS3(sqs, "queueUrl", s3, "bucket", new byte[] { 1, 2 });
} catch (RuntimeException e) {
assertTrue(e instanceof CompositeException);
InOrder inorder = Mockito.inOrder(sqs, s3);
inorder.verify(s3, Mockito.times(1)).putObject(Mockito.anyString(), Mockito.anyString(), Mockito.any(),
Mockito.any());
inorder.verify(sqs, Mockito.times(1)).sendMessage(Mockito.anyString(), Mockito.anyString());
inorder.verify(s3, Mockito.times(1)).deleteObject(Mockito.anyString(), Mockito.anyString());
inorder.verifyNoMoreInteractions();
}
}
示例12: deleteMessageFromFactoryWhenS3FactoryExists
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
@Test
public void deleteMessageFromFactoryWhenS3FactoryExists() {
AmazonSQSClient sqs = Mockito.mock(AmazonSQSClient.class);
AmazonS3Client s3 = Mockito.mock(AmazonS3Client.class);
String s3Id = "123";
SqsMessage m = new SqsMessage(RECEIPT_HANDLE, new byte[] {}, 1000, Optional.of(s3Id),
new SqsMessage.Service(Optional.of(() -> s3), () -> sqs, Optional.of(s3), sqs,
QUEUE, Optional.of(BUCKET)));
Mockito.when(sqs.deleteMessage(QUEUE, RECEIPT_HANDLE))
.thenReturn(new DeleteMessageResult());
m.deleteMessage(Client.FROM_FACTORY);
InOrder inorder = Mockito.inOrder(sqs, s3);
inorder.verify(s3, Mockito.times(1)).deleteObject(BUCKET, s3Id);
inorder.verify(sqs, Mockito.times(1)).deleteMessage(QUEUE, RECEIPT_HANDLE);
inorder.verify(s3, Mockito.times(1)).shutdown();
inorder.verify(sqs, Mockito.times(1)).shutdown();
Mockito.verifyNoMoreInteractions(sqs, s3);
}
示例13: initQueue
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的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.AmazonSQSClient; //导入依赖的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: scanSQS
import com.amazonaws.services.sqs.AmazonSQSClient; //导入依赖的package包/类
/**
* Collect data for SQS.
*
* @param stats
* current statistics object.
* @param account
* currently used credentials object.
* @param region
* currently used aws region.
*/
public static void scanSQS(AwsStats stats, AwsAccount account, Regions region) {
LOG.debug("Scan for SQS in region " + region.getName() + " in account " + account.getAccountId());
try {
AmazonSQSClient sqs = new AmazonSQSClient(account.getCredentials());
sqs.setRegion(Region.getRegion(region));
int totalQueues = 0;
for (String queueUrl : sqs.listQueues().getQueueUrls()) {
AwsResource res = new AwsResource(queueUrl, account.getAccountId(), AwsResourceType.SQS, region);
stats.add(res);
totalQueues++;
}
LOG.info(totalQueues + " SQS queues in region " + region.getName() + " in account " + account.getAccountId());
} catch (AmazonServiceException ase) {
LOG.error("Exception of SQS: " + ase.getMessage());
} catch (Exception ex) {
LOG.error("Exception of SQS: " + ex.getMessage());
}
}