本文整理汇总了Java中com.amazonaws.services.sqs.model.Message类的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于com.amazonaws.services.sqs.model包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
public List<S3SNSNotification> parse(Message message) {
List<S3SNSNotification> notifications = Lists.newArrayList();
try {
SQSMessage envelope = om.readValue(message.getBody(), SQSMessage.class);
if (envelope.message == null) {
return Collections.emptyList();
}
S3EventNotification s3EventNotification = S3EventNotification.parseJson(envelope.message);
notifications.addAll(s3EventNotification.getRecords().stream().map(record -> new S3SNSNotification(
message.getReceiptHandle(),
record.getS3().getBucket().getName(),
record.getS3().getObject().getUrlDecodedKey()
)).collect(Collectors.toList()));
} catch (Exception e) {
LOG.error("Could not parse SNS notification: " + message.getBody(), e);
throw new RuntimeException("Could not parse SNS notification: " + message.getBody(), e);
}
return notifications;
}
示例2: getMessages
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
public List<QueueMessage> getMessages() {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(_queueDns);
List<Message> messages = _sqs.receiveMessage(receiveMessageRequest).getMessages();
List<QueueMessage> deserializedMessages = new ArrayList<>();
for (Message message : messages) {
String body = message.getBody();
QueueMessage qm = _gson.fromJson(body, QueueMessage.class);
deserializedMessages.add(qm);
System.out.println("query time: " + qm.queryExecutionTime);
System.out.println("exec time: " + qm.totalExecutionTime);
System.out.println("Has ex: " + qm.hasException);
System.out.println("ex message: " + qm.exceptionMessage + "\n");
String receiptHandle = message.getReceiptHandle();
_sqs.deleteMessage(new DeleteMessageRequest(_queueDns, receiptHandle));
}
return deserializedMessages;
}
示例3: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
示例4: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
示例5: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
示例6: parseMessage
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
@Override
public List<Event> parseMessage(final Message message) {
List<Event> events = Collections.emptyList();
try {
MessageBody body = gson.fromJson(message.getBody(), MessageBody.class);
final String json = body.getMessage();
log.debug("Parse message %s", json);
if (StringUtils.isEmpty(json)) {
log.warning("Message contains no text");
return Collections.emptyList();
}
if (!json.startsWith("{") || !json.endsWith("}")) {
log.warning("Message text is no JSON");
return Collections.emptyList();
}
events = this.parseRecords(json);
} catch (final com.google.gson.JsonSyntaxException e) {
log.error("JSON syntax exception, cannot parse message: %s", e);
}
return events;
}
示例7: handleMessage
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
private boolean handleMessage(final Message message) {
log.debug("Parse and do match against events, message: %s", this.job, message.getBody());
final MessageParser parser = this.messageParserFactory.createParser(message);
final List<Event> events = parser.parseMessage(message);
boolean matched = this.eventTriggerMatcher.matches(events, this.sqsJob);
String messageId = com.ribose.jenkins.plugin.awscodecommittrigger.utils.StringUtils.getMessageId(message);
log.info("Any event matched? %s. Message: %s", this.job, matched, messageId);
if (matched) {
log.debug("Hurray! Execute it", this.job);
//TODO use java8 lambda for this loop
List<String> userarns = new ArrayList<>();
for (Event event : events) {
userarns.add(event.getUser());
}
this.execute(message, userarns);
return true;
}
return false;
}
示例8: processTask
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
private void processTask(Message message) {
String path = message.getBody();
PathSplit pathComp = new PathSplit(path);
String bucket = pathComp.bucket;
String key = pathComp.key;
Logger.Info("Processing %s %s", bucket, key);
// Rekognition: Detect Labels from S3 object
DetectLabelsRequest req = new DetectLabelsRequest()
.withImage(new Image().withS3Object(new S3Object().withBucket(bucket).withName(key)))
.withMinConfidence(minConfidence);
DetectLabelsResult result;
result = rek.detectLabels(req);
List<Label> labels = result.getLabels();
Logger.Debug("In %s, found: %s", key, labels);
// Process downstream actions:
for (LabelProcessor processor : processors) {
processor.process(labels, path);
}
}
示例9: claimScanRangeTasks
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
@Override
public List<ScanRangeTask> claimScanRangeTasks(int max, Duration ttl) {
if (max == 0) {
return ImmutableList.of();
}
List<Message> messages = _sqs.receiveMessage(new ReceiveMessageRequest()
.withQueueUrl(getQueueUrl(_pendingScanRangeQueue))
.withMaxNumberOfMessages(Math.min(max, 10)) // SQS cannot claim more than 10 messages
.withVisibilityTimeout(toSeconds(ttl))
).getMessages();
return FluentIterable.from(messages)
.transform(new Function<Message, ScanRangeTask>() {
@Override
public ScanRangeTask apply(Message message) {
QueueScanRangeTask task = JsonHelper.fromJson(message.getBody(), QueueScanRangeTask.class);
task.setMessageId(message.getReceiptHandle());
return task;
}
})
.toList();
}
示例10: claimCompleteScanRanges
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
@Override
public List<ScanRangeComplete> claimCompleteScanRanges(Duration ttl) {
List<Message> messages = _sqs.receiveMessage(new ReceiveMessageRequest()
.withQueueUrl(getQueueUrl(_completeScanRangeQueue))
.withMaxNumberOfMessages(10)
.withVisibilityTimeout(toSeconds(ttl))
).getMessages();
return FluentIterable.from(messages)
.transform(new Function<Message, ScanRangeComplete>() {
@Override
public ScanRangeComplete apply(Message message) {
QueueScanRangeComplete completion = JsonHelper.fromJson(message.getBody(), QueueScanRangeComplete.class);
completion.setMessageId(message.getReceiptHandle());
return completion;
}
})
.toList();
}
示例11: pollMessages
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
}
}
示例12: testFirstCallToReceiveMessagesReturnsOneMessage
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
示例13: testFirstCallToReceiveMessagesReturnsOneMessageAndHonoursBackpressure
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
示例14: testFirstCallToReceiveMessagesReturnsNoMessagesThenSecondCallReturnsTwoMessages
import com.amazonaws.services.sqs.model.Message; //导入依赖的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();
}
示例15: defaultsToDisabled
import com.amazonaws.services.sqs.model.Message; //导入依赖的package包/类
@Test
public void defaultsToDisabled() throws Exception {
this.mock.expectedMessageCount(1);
this.mock.whenAnyExchangeReceived(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
// Simulate message that takes a while to receive.
Thread.sleep(TIMEOUT * 1500L); // 150% of TIMEOUT.
}
});
Message message = new Message();
message.setBody("Message 1");
message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
message.setReceiptHandle(RECEIPT_HANDLE);
this.clientMock.messages.add(message);
assertMockEndpointsSatisfied(); // Wait for message to arrive.
assertTrue("Expected no changeMessageVisibility requests.", this.clientMock.changeMessageVisibilityRequests.size() == 0);
}