當前位置: 首頁>>代碼示例>>Java>>正文


Java Message類代碼示例

本文整理匯總了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;
}
 
開發者ID:sherzberg,項目名稱:graylog-plugin-s3,代碼行數:25,代碼來源:S3SNSNotificationParser.java

示例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;
    }
 
開發者ID:hunterSThompson,項目名稱:aws-ski-resort,代碼行數:24,代碼來源:QueueService.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava2-aws,代碼行數:24,代碼來源:SqsTest.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava2-aws,代碼行數:24,代碼來源:SqsTest.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava2-aws,代碼行數:25,代碼來源:SqsTest.java

示例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;
}
 
開發者ID:riboseinc,項目名稱:aws-codecommit-trigger-plugin,代碼行數:27,代碼來源:CodeCommitMessageParser.java

示例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;
}
 
開發者ID:riboseinc,項目名稱:aws-codecommit-trigger-plugin,代碼行數:25,代碼來源:SQSTrigger.java

示例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);
    }
}
 
開發者ID:jhy,項目名稱:RekognitionS3Batch,代碼行數:22,代碼來源:Processor.java

示例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();
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:24,代碼來源:SQSScanWorkflow.java

示例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();
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:20,代碼來源:SQSScanWorkflow.java

示例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();
        }
    }
}
 
開發者ID:thingsboard,項目名稱:thingsboard,代碼行數:19,代碼來源:SqsDemoClient.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava-aws,代碼行數:24,代碼來源:SqsTest.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava-aws,代碼行數:24,代碼來源:SqsTest.java

示例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();
}
 
開發者ID:davidmoten,項目名稱:rxjava-aws,代碼行數:25,代碼來源:SqsTest.java

示例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);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:22,代碼來源:SqsDoesNotExtendMessageVisibilityTest.java


注:本文中的com.amazonaws.services.sqs.model.Message類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。