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


Java AmazonSNS.publish方法代码示例

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


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

示例1: execute

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
@Override
public void execute(PostDownloadExecution execution) {

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretAccessKey);

    AmazonSNS sns = snsClientBuilder.withRegion(region)
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();

    LOGGER.debug("SNS: Topic Arn               : {}", arn);
    LOGGER.debug("SNS: Topic Region            : {}", region);
    LOGGER.debug("SNS: Topic Access Key        : {}", accessKey);
    LOGGER.debug("SNS: Topic Secret Access Key : {}", secretAccessKey);

    PublishRequest request = new PublishRequest();
    request.setTopicArn(arn);
    request.setMessageStructure("json");
    request.setMessage(formatJsonMessage(execution.fileName));
    request.setSubject("A new file has been downloaded");

    LOGGER.info("Publishing message to SNS");
    PublishResult result = sns.publish(request);
    LOGGER.info("Publish successful!");
    LOGGER.debug("{}", result.getMessageId());
}
 
开发者ID:linuxserver,项目名称:davos,代码行数:25,代码来源:SNSNotifyAction.java

示例2: sendPushMessage

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public PublishResult sendPushMessage(AmazonSNS snsClient, PushPlatform platform, String targetArn, String message,
		Map<String, MessageAttributeValue> messageAttributes) throws IOException {
	Map<String, String> messageMap = new HashMap<String, String>();
	messageMap.put(platform.name(), message);
	message = ServerUtil.asJson(messageMap);

    PublishRequest publishRequest = new PublishRequest();
	publishRequest.setMessageStructure("json");
	
	if (messageAttributes != null) {
		publishRequest.setMessageAttributes(messageAttributes);
	}

	publishRequest.setTargetArn(targetArn);
	publishRequest.setMessage(message);

	PublishResult publishResult = snsClient.publish(publishRequest);

	return publishResult;
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:21,代码来源:PushSnsService.java

示例3: publishAndReceiveSeparateSQSClients

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public void publishAndReceiveSeparateSQSClients() {
    final String queueName = someQueueName();
    final String queueUrl = someNewQueue(queueName);
    final String topicName = "publishAndReceiveSeparateSQSClients";
    final String message = "hi from " + topicName;

    AmazonSNS amazonSNS = new InMemorySNS(_amazonSQS1,
            new Subscription().
                    withTopicArn(makeTopicArn(topicName)).
                    withProtocol("sqs").
                    withSubscriptionArn(makeSomeSubArn(topicName)).
                    withEndpoint(getQueueArn(queueName)));

    amazonSNS.publish(new PublishRequest(makeTopicArn(topicName), message));

    ReceiveMessageResult result = _amazonSQS2.receiveMessage(new ReceiveMessageRequest(queueUrl).
            withWaitTimeSeconds(15));
    Assert.assertEquals(result.getMessages().size(), 1);
    Assert.assertEquals(result.getMessages().get(0).getBody(), message);
}
 
开发者ID:bazaarvoice,项目名称:awslocal,代码行数:21,代码来源:TestSNSClient.java

示例4: postMessage

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的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

示例5: publishAndReceive

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public void publishAndReceive() {
    final String queueName = someQueueName();
    final String queueUrl = someNewQueue(queueName);
    final String topicName = "publishAndReceive";
    final String message = "hi from " + topicName;

    AmazonSNS amazonSNS = new InMemorySNS(_amazonSQS1,
            new Subscription().
                    withTopicArn(makeTopicArn(topicName)).
                    withProtocol("sqs").
                    withSubscriptionArn(makeSomeSubArn(topicName)).
                    withEndpoint(getQueueArn(queueName)));

    Assert.assertEquals(amazonSNS.listTopics().getTopics().size(), 1);
    Assert.assertEquals(amazonSNS.listSubscriptions().getSubscriptions().size(), 1);
    Assert.assertEquals(amazonSNS.
            listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(makeTopicArn(topicName)))
            .getSubscriptions()
            .size(),
            1);


    amazonSNS.publish(new PublishRequest(makeTopicArn(topicName), message));
    ReceiveMessageResult result = _amazonSQS1.receiveMessage(new ReceiveMessageRequest(queueUrl));
    Assert.assertEquals(result.getMessages().size(), 1);
    Assert.assertEquals(result.getMessages().get(0).getBody(), message);
}
 
开发者ID:bazaarvoice,项目名称:awslocal,代码行数:28,代码来源:TestSNSClient.java

示例6: manualSubscriptionSetup

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public void manualSubscriptionSetup() {
    final String queueName = someQueueName();
    final String queueUrl = someNewQueue(queueName);
    final String topicName = "manualSubscriptionSetup";
    final String message = "hi from " + topicName;

    AmazonSNS amazonSNS = new InMemorySNS(_amazonSQS1);

    amazonSNS.createTopic(new CreateTopicRequest(topicName));
    Assert.assertEquals(amazonSNS.listTopics().getTopics().size(), 1);
    Assert.assertEquals(amazonSNS.listTopics().getTopics().get(0).getTopicArn(), makeTopicArn(topicName));

    //make sure create is idempotent
    amazonSNS.createTopic(new CreateTopicRequest(topicName));
    Assert.assertEquals(amazonSNS.listTopics().getTopics().size(), 1, "existing topic duplicated?");
    Assert.assertEquals(amazonSNS.listTopics().getTopics().get(0).getTopicArn(), makeTopicArn(topicName));

    //subscribe.
    amazonSNS.subscribe(new SubscribeRequest().
            withEndpoint(getQueueArn(queueName)).
            withProtocol("sqs").
            withTopicArn(makeTopicArn(topicName)));

    Assert.assertEquals(amazonSNS.listSubscriptions().getSubscriptions().size(), 1);
    Assert.assertEquals(amazonSNS.listSubscriptions().getSubscriptions().get(0).getTopicArn(), makeTopicArn(topicName));
    Assert.assertEquals(amazonSNS.
            listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(makeTopicArn(topicName)))
            .getSubscriptions()
            .size(),
            1);

    amazonSNS.publish(new PublishRequest(makeTopicArn(topicName), message));

    ReceiveMessageResult result = _amazonSQS1.receiveMessage(new ReceiveMessageRequest(queueUrl));
    Assert.assertEquals(result.getMessages().size(), 1);
    Assert.assertEquals(result.getMessages().get(0).getBody(), message);
}
 
开发者ID:bazaarvoice,项目名称:awslocal,代码行数:38,代码来源:TestSNSClient.java

示例7: publish

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
@Override
public PublishResult publish(String topicArn, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSNS amazonSNS)
{
    return amazonSNS.publish(new PublishRequest().withTopicArn(topicArn).withMessage(messageText).withMessageAttributes(messageAttributes));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:6,代码来源:SnsOperationsImpl.java

示例8: process

import com.amazonaws.services.sns.AmazonSNS; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {

		// TODO cache arns and don't create if not necessary
		final String topic = determineTopic(exchange);

		// creates a new topic, or returns the URL of an existing one
		CreateTopicRequest request = new CreateTopicRequest(topic);

		LOG.trace("Creating topic [{}] with request [{}]...", topic, request);

		final AmazonSNS snsClient = getEndpoint().getSNSClient();
		
		CreateTopicResult result = snsClient.createTopic(request);

		final String topicArn = result.getTopicArn();
		LOG.trace("Topic created with Amazon resource name: {}", topicArn);

		final SnsConfiguration configuration = getEndpoint().getConfiguration();
		
		if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
			LOG.trace("Updating topic [{}] with policy [{}]", topicArn, configuration.getPolicy());

			snsClient.setTopicAttributes(
					new SetTopicAttributesRequest(topicArn, "Policy", configuration.getPolicy()));

			LOG.trace("Topic policy updated");
		}

		PublishRequest publishRequest = new PublishRequest();

		publishRequest.setTopicArn(topicArn);
		publishRequest.setSubject(determineSubject(exchange));
		publishRequest.setMessageStructure(determineMessageStructure(exchange));
		publishRequest.setMessage(exchange.getIn().getBody(String.class));

		LOG.trace("Sending request [{}] from exchange [{}]...", publishRequest, exchange);

		PublishResult publishResult = snsClient.publish(publishRequest);

		LOG.trace("Received result [{}]", publishResult);

		Message message = getMessageForResponse(exchange);
		message.setHeader(SnsConstants.MESSAGE_ID, publishResult.getMessageId());
	}
 
开发者ID:highsource,项目名称:aufzugswaechter,代码行数:45,代码来源:DynamicSnsProducer.java


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