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


Java AmazonSNSClient.publish方法代码示例

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


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

示例1: run

import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
@Override
public void run(Webhook webhook, String login, String email, String name, String subject, String content) {

    SNSWebhookApp webhookApp = (SNSWebhookApp) webhook.getWebhookApp();
    String topicArn = webhookApp.getTopicArn();
    String awsAccount = webhookApp.getAwsAccount();
    String awsSecret = webhookApp.getAwsSecret();
    String region = webhookApp.getRegion();
    AmazonSNSClient snsClient = new AmazonSNSClient(new BasicAWSCredentials(awsAccount, awsSecret));
    snsClient.setRegion(Region.getRegion(Regions.fromName(region)));

    try {
        PublishRequest publishReq = new PublishRequest()
                .withTopicArn(topicArn)
                .withMessage(getMessage(login, email, name, subject, content));
        snsClient.publish(publishReq);

    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Cannot send notification to SNS service", e);
    } finally {
        LOGGER.log(Level.INFO, "Webhook runner terminated");
    }
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:24,代码来源:SNSWebhookRunner.java

示例2: publish

import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
public static boolean publish(String arn, String msg, AmazonSNSClient snsClient, String s3Key) {
  if (dryRun) {
    logger.warn("would have published " + s3Key + " S3 creation event to SNS");
    return true;
  }

  logger.info("publishing " + s3Key + " S3 creation event to SNS");

  try {
    snsClient.publish(arn, msg, "Amazon S3 Notification");
  } catch (RuntimeException e) {
    logger.error("error publishing", e);
    return false;
  }

  return true;
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:18,代码来源:S3SnsNotifier.java

示例3: main

import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

		final AmazonSNSClient client = Region.getRegion(Regions.EU_CENTRAL_1).createClient(AmazonSNSClient.class, null,
				null);
		CreateTopicResult createTopic = client.createTopic("facilities");
		createTopic.getTopicArn();
		SubscribeResult subscribe = client.subscribe(createTopic.getTopicArn(), "email", "[email protected]");
		final PublishRequest publishRequest = new PublishRequest(createTopic.getTopicArn(), "Test message");
		client.publish(publishRequest);
	}
 
开发者ID:highsource,项目名称:aufzugswaechter,代码行数:11,代码来源:HelloWorldSNS.java

示例4: onException

import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
@Override
public void onException(Exception e) {
  /*
   * Always close the iterator to prevent connection leaking
   */
  try {
    if (this.recordIterator != null) {
      this.recordIterator.close();
    }
  } catch (IOException e1) {
    logger.error("unable to close record iterator", e);
  }

  if (this.config == null || this.config.getHandlerConfig() == null) {
    return;
  }

  /*
   * Notify SNS topic
   */
  SNSS3HandlerConfig handlerConfig = (SNSS3HandlerConfig) this.config.getHandlerConfig();
  if (handlerConfig.getSnsNotificationArn() != null) {
    AmazonSNSClient snsClient = this.snsClientFactory.newInstance();
    snsClient.publish(handlerConfig.getSnsNotificationArn(),
        this.inputFiles.stream().map(Object::toString).collect(Collectors.joining(",")),
        "SNSS3Handler Failed");
  }
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:29,代码来源:SNSS3Handler.java

示例5: handleRequest

import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
public String handleRequest(Context context) throws IOException {
  LambdaLogger logger = context.getLogger();
  logger.log("handleRequest start.");
  ObjectMapper mapper = new ObjectMapper();
  JsonObject json = mapper.readValue(new URL(IP_RANGE_URL), JsonObject.class);

  AmazonS3Client s3 = getS3Client();
  Properties props = getProperties();
  s3.setEndpoint(props.getProperty("s3.endpoint"));

  GetObjectRequest request = new GetObjectRequest(props.getProperty(S3_BUCKETNAME_KEY), CHECKED_FILE_NAME);
  try {
    S3Object beforeObject = s3.getObject(request);
    InputStream is = beforeObject.getObjectContent();
    JsonObject beforeJson = mapper.readValue(is, JsonObject.class);
    Optional<String> diff = beforeJson.getDiff(json);
    if (diff.isPresent()) {
      AmazonSNSClient sns = getSNSClient();
      sns.setRegion(Region.getRegion(Regions.fromName(props.getProperty("sns.region"))));
      PublishRequest publishRequest = new PublishRequest(props.getProperty("sns.topic.arn"), diff.get(), SNS_SUBJECT);
      PublishResult result = sns.publish(publishRequest);
      logger.log("send sns message. messageId = " + result.getMessageId());
    }
  } catch (AmazonS3Exception e) {
    logger.log("before checked-ip-ranges.json does not exist.");
  }
  storeCheckedIpRange(json);
  logger.log("stored checked-ip-ranges.json");
  return "success";
}
 
开发者ID:haw-itn,项目名称:aws-iprange-update-checker,代码行数:31,代码来源:RangeCheckHandler.java

示例6: publishToSnsTopic

import com.amazonaws.services.sns.AmazonSNSClient; //导入方法依赖的package包/类
private void publishToSnsTopic(String topicARN, String messageBody, int badgeNum, String soundName, Boolean isDebug) throws PushSnsSenderCustomException {

        theLogger.info("publishToSnsTopic has been called for topicARN:{} with messageBody:{}, badgeNum:{}, soundName:{} and isDebug:{}", topicARN, messageBody, badgeNum, soundName, isDebug);

        //check th params
        if (topicARN == null || messageBody == null) {
            throw new PushSnsSenderCustomException("Cannot send SNS notification because topicARN or messageBody is empty!");
        }

        //create AWS credentials
        if (awsAccessKey == null || awsSecretKey == null) {
            theLogger.error("AWS credentials not configured!");
            throw new PushSnsSenderCustomException("Internal server error!");   //say something via web
        }
        else {
            awsCreds = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
        }

        //create a new SNS client with credentials
        AmazonSNSClient snsClient = new AmazonSNSClient(awsCreds);
        snsClient.setRegion(Region.getRegion(Regions.US_EAST_1));

        //publish to an SNS topic
        try {

            //Request
            PublishRequest publishRequest = new PublishRequest();
            SnsAppleNotificationTemplate appleNotificationTemplate = new SnsAppleNotificationTemplate(topicARN,
                                                                                                      messageBody,
                                                                                                      badgeNum,
                                                                                                      soundName,
                                                                                                      isDebug);

            publishRequest.setMessage(appleNotificationTemplate.toSnSAppleString());
            publishRequest.setMessageStructure("json");
            publishRequest.setTopicArn(topicARN);

            PublishResult publishResult = snsClient.publish(publishRequest);

            //print MessageId of message published to SNS topic
            theLogger.info("MessageId: {} was successfully published", publishResult.getMessageId());

        }

        catch (Exception theException) {
            //theLogger.error("Cannot send SNS notification! Exception: " + theException);
            throw new PushSnsSenderCustomException("publishToSnsTopic: Cannot send SNS notification! Exception: " + theException);
        }

        finally {
            snsClient.shutdown();
        }

    }
 
开发者ID:bigMOTOR,项目名称:PushSnsSender,代码行数:55,代码来源:SnsSenderController.java


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