当前位置: 首页>>代码示例>>Java>>正文


Java SNSEvent.SNSRecord方法代码示例

本文整理汇总了Java中com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord方法的典型用法代码示例。如果您正苦于以下问题:Java SNSEvent.SNSRecord方法的具体用法?Java SNSEvent.SNSRecord怎么用?Java SNSEvent.SNSRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.lambda.runtime.events.SNSEvent的用法示例。


在下文中一共展示了SNSEvent.SNSRecord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSnsEvent

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入方法依赖的package包/类
private SNSEvent createSnsEvent(final String githubEvent) {
    SNSEvent.SNS sns = new SNSEvent.SNS();
    sns.setMessageAttributes(new HashMap<String, SNSEvent.MessageAttribute>(1, 1) {
        {
            SNSEvent.MessageAttribute attr = new SNSEvent.MessageAttribute();
            attr.setValue(githubEvent);
            put("X-Github-Event", attr);
        }
    });
    try (InputStream is = getClass().getResourceAsStream("/github-push-payload.json")) {
        sns.setMessage(IOUtils.toString(is));
    }
    catch (IOException e) {
        throw new IllegalArgumentException(e);
    }

    SNSEvent.SNSRecord record = new SNSEvent.SNSRecord();
    record.setSns(sns);

    SNSEvent snsEvent = new SNSEvent();
    snsEvent.setRecords(Collections.singletonList(record));
    return snsEvent;
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:24,代码来源:LambdaTest.java

示例2: handleRequest

import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入方法依赖的package包/类
public Integer handleRequest(SNSEvent event, Context context) {
    try {
        // SNS Events could be possible more than one even if this looks a bit unusual for the deploy case.
        for (SNSEvent.SNSRecord record : event.getRecords()) {
            SNSEvent.SNS sns = record.getSNS();
            // Check SNS header for event type.
            SNSEvent.MessageAttribute attr = sns.getMessageAttributes().get(X_GITHUB_EVENT);
            // Only watch pushes to master.
            if (EVENT_PUSH.equalsIgnoreCase(attr.getValue())) {
                PushPayload value = MAPPER.readValue(sns.getMessage(), PushPayload.class);
                if (config.isWatchedBranch(new Branch(value.getRef()))) {
                    LOG.info(format("Processing '%s' on '%s': '%s'", attr.getValue(), value.getRef(), value.getHeadCommit().getId()));
                    switch (worker.call()) {
                        case SUCCESS:
                            return HttpStatus.SC_OK;
                        case FAILED:
                            return HttpStatus.SC_BAD_REQUEST;
                    }
                }
                // Different branch was found.
                else {
                    LOG.info(format("Push received for: '%s'", value.getRef()));
                }
            }
            // Different event was found.
            else {
                LOG.info(format("Event was: '%s'", attr.getValue()));
            }
        }
    }
    catch (Exception e) {
        LOG.error(e.getMessage(), e);
        return HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }
    return HttpStatus.SC_BAD_REQUEST;
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:37,代码来源:Lambda.java


注:本文中的com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。