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


Java AmazonSNSClient类代码示例

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


AmazonSNSClient类属于com.amazonaws.services.sns包,在下文中一共展示了AmazonSNSClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CreateCloudFrontSecurityGroupUpdaterLambdaOperation

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
@Inject
public CreateCloudFrontSecurityGroupUpdaterLambdaOperation(final CloudFormationService cloudFormationService,
                                                           final EnvironmentMetadata environmentMetadata,
                                                           @Named(CF_OBJECT_MAPPER) final ObjectMapper cloudformationObjectMapper,
                                                           AWSLambda awsLambda,
                                                           AmazonS3 amazonS3) {

    this.cloudFormationService = cloudFormationService;
    this.cloudformationObjectMapper = cloudformationObjectMapper;
    this.environmentMetadata = environmentMetadata;
    this.awsLambda = awsLambda;
    this.amazonS3 = amazonS3;

    final Region region = Region.getRegion(Regions.US_EAST_1);
    AmazonCloudFormation amazonCloudFormation = new AmazonCloudFormationClient();
    amazonCloudFormation.setRegion(region);
    amazonSNS = new AmazonSNSClient();
    amazonSNS.setRegion(region);
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:20,代码来源:CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java

示例4: 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

示例5: getSNS

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
private static AmazonSNS getSNS() throws IOException {
	String awsAccessKey = System.getProperty("AWS_ACCESS_KEY_ID"); // "YOUR_AWS_ACCESS_KEY";
	String awsSecretKey = System.getProperty("AWS_SECRET_KEY"); // "YOUR_AWS_SECRET_KEY";

	if (awsAccessKey == null)
		awsAccessKey = AWS_ACCESS_KEY;
	if (awsSecretKey == null)
		awsSecretKey = AWS_SECRET_KEY;

	AWSCredentials credentials = new BasicAWSCredentials(awsAccessKey,
			awsSecretKey);
	AmazonSNS sns = new AmazonSNSClient(credentials);

	sns.setEndpoint("https://sns.us-west-2.amazonaws.com");
	return sns;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:17,代码来源:SNSMobilePush.java

示例6: assertNoStaleTopic

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
public static void assertNoStaleTopic(AmazonSNSClient client, String when) {
    /* Remove the topic created by the the old version of this test. Note that this may break the old tests running
     * in parallel. */
    client.listTopics().getTopics().stream()
            .filter(topic -> topic.getTopicArn().endsWith("MyNewTopic"))
            .forEach(t -> client.deleteTopic(t.getTopicArn()));
    List<String> staleInstances = client.listTopics().getTopics().stream() //
            .map(topic -> topic.getTopicArn().substring(topic.getTopicArn().lastIndexOf(':') + 1)) // extract the
                                                                                                   // topic name
                                                                                                   // from the ARN
            .filter(name -> !name.startsWith(SNSIntegrationTest.class.getSimpleName())
                    || System.currentTimeMillis() - AWSUtils.toEpochMillis(name) > AWSUtils.HOUR) //
            .collect(Collectors.toList());
    Assert.assertEquals(String.format("Found stale SNS topics %s running the test: %s", when, staleInstances), 0,
            staleInstances.size());
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:17,代码来源:SNSIntegrationTest.java

示例7: createAWSClient

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
@Override
protected void createAWSClient()
{
    client = tryClientFactory(config.clientFactoryMethod, AmazonSNS.class, true);
    if ((client == null) && (config.clientEndpoint == null))
    {
        client = tryClientFactory("com.amazonaws.services.sns.AmazonSNSClientBuilder.defaultClient", AmazonSNS.class, false);
    }
    if (client == null)
    {
        LogLog.debug(getClass().getSimpleName() + ": creating service client via constructor");
        client = tryConfigureEndpointOrRegion(new AmazonSNSClient(), config.clientEndpoint);
    }
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:15,代码来源:SNSLogWriter.java

示例8: postMessage

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
/**
 * Sends using the sns publisher
 */
@Override
public boolean postMessage(NotificationMessage nMsg,
                           BasicSubscriber subscriber) {

    SNSSubscriber sub;
    if (subscriber instanceof SNSSubscriber) {
        sub = (SNSSubscriber) subscriber;
    } else {
        throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName());
    }

    SNSMessage msg = buildSNSMessage(nMsg);
    AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey()));
    if (sub.getSnsEndpoint() != null) {
        sns.setEndpoint(sub.getSnsEndpoint());
    }

    CreateTopicRequest tRequest = new CreateTopicRequest();
    tRequest.setName(msg.getTopicName());
    CreateTopicResult result = sns.createTopic(tRequest);

    PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage()).withSubject(msg.getSubject());

    try {
        PublishResult pubresult = sns.publish(pr);
        logger.info("Published msg with id - " + pubresult.getMessageId());
    } catch (AmazonClientException ace) {
        logger.error(ace.getMessage());
        return false;
    }
    return true;
}
 
开发者ID:oneops,项目名称:oneops,代码行数:36,代码来源:SNSService.java

示例9: 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

示例10: testExceptionHandlingd

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
@Test
public void testExceptionHandlingd() throws Throwable {
  BaseHandler.CONFIG_FILE = "/com/nextdoor/bender/handler/config_test_sns.json";

  TestContext ctx = new TestContext();
  ctx.setFunctionName("unittest");
  ctx.setInvokedFunctionArn("arn:aws:lambda:us-east-1:123:function:test-function:staging");

  /*
   * Invoke handler
   */
  SNSS3Handler fhandler = (SNSS3Handler) getHandler();
  fhandler.init(ctx);

  IpcSenderService ipcSpy = spy(fhandler.getIpcService());
  doThrow(new TransportException("expected")).when(ipcSpy).shutdown();
  fhandler.setIpcService(ipcSpy);

  AmazonSNSClient mockClient = mock(AmazonSNSClient.class);
  AmazonSNSClientFactory mockClientFactory = mock(AmazonSNSClientFactory.class);
  doReturn(mockClient).when(mockClientFactory).newInstance();

  fhandler.snsClientFactory = mockClientFactory;

  SNSEvent event = getTestEvent();

  try {
    fhandler.handler(event, ctx);
  } catch (Exception e) {
  }
  verify(mockClient, times(1)).publish("foo", "basic_input.log", "SNSS3Handler Failed");
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:33,代码来源:SNSS3HandlerTest.java

示例11: provideAmazonSNS

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
@Provides
@Singleton
protected AmazonSNS provideAmazonSNS(Region region, AWSCredentialsProvider credentialsProvider) {
    AmazonSNS amazonSNS = new AmazonSNSClient(credentialsProvider);
    amazonSNS.setRegion(region);
    return amazonSNS;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:8,代码来源:ScanUploadModule.java

示例12: init

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
private void init() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(configuration.getAccessKeyId(), configuration.getSecretAccessKey());
    AWSStaticCredentialsProvider credProvider = new AWSStaticCredentialsProvider(awsCredentials);
    AmazonSNS sns = AmazonSNSClient.builder()
            .withCredentials(credProvider)
            .withRegion(configuration.getRegion())
            .build();
    this.snsMessageHandler = new SnsMessageHandler(sns);

}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:11,代码来源:SnsPlugin.java

示例13: configure

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
/**
 * Binds all the Amazon services used.
 */
@Override
protected void configure() {
    final Region region = Region.getRegion(Regions.fromName(regionName));
    bind(AmazonEC2.class).toInstance(createAmazonClientInstance(AmazonEC2Client.class, region));
    bind(AmazonCloudFormation.class).toInstance(createAmazonClientInstance(AmazonCloudFormationClient.class, region));
    bind(AmazonIdentityManagement.class).toInstance(createAmazonClientInstance(AmazonIdentityManagementClient.class, region));
    bind(AWSKMS.class).toInstance(createAmazonClientInstance(AWSKMSClient.class, region));
    bind(AmazonS3.class).toInstance(createAmazonClientInstance(AmazonS3Client.class, region));
    bind(AmazonAutoScaling.class).toInstance(createAmazonClientInstance(AmazonAutoScalingClient.class, region));
    bind(AWSSecurityTokenService.class).toInstance(createAmazonClientInstance(AWSSecurityTokenServiceClient.class, region));
    bind(AWSLambda.class).toInstance(createAmazonClientInstance(AWSLambdaClient.class, region));
    bind(AmazonSNS.class).toInstance(createAmazonClientInstance(AmazonSNSClient.class, region));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:17,代码来源:CerberusModule.java

示例14: 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

示例15: getSNSClient

import com.amazonaws.services.sns.AmazonSNSClient; //导入依赖的package包/类
private AmazonSNSClient getSNSClient() {
  Optional<AWSCredentials> credentials = getCredentials();
  if (credentials.isPresent()) {
    return new AmazonSNSClient(credentials.get());
  } else {
    return new AmazonSNSClient(new EnvironmentVariableCredentialsProvider());
  }
}
 
开发者ID:haw-itn,项目名称:aws-iprange-update-checker,代码行数:9,代码来源:RangeCheckHandler.java


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