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


Java PublishResult类代码示例

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


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

示例1: testPublish_shouldPublishTheMessage

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Test
public void testPublish_shouldPublishTheMessage() {
  CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("important-topic"));
  
  PublishRequest publishReq = new PublishRequest()
      .withMessage("{\"state\":\"liquid\",\"color\":\"black\",\"waking-up\":true}")
      .withMessageStructure("json")
      .withPhoneNumber("00121212")
      .withSubject("eeffoc")
      .withTopicArn(topicResult.getTopicArn());
  
  PublishResult publishResult = sns.publish(publishReq);
  assertNotNull("verify message id",publishResult.getMessageId());
  
  Topic topic = getSnsTopics().get(topicResult.getTopicArn());
  assertEquals("verify correct message count", 1, topic.getMessages().size());
  assertEquals("verify message subject","eeffoc",topic.getMessages().get(0).getSubject());
  assertEquals("verify message body","{\"state\":\"liquid\",\"color\":\"black\",\"waking-up\":true}",topic.getMessages().get(0).getBody());
  assertEquals("verify message structure","json",topic.getMessages().get(0).getStructure());
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:21,代码来源:MockSnsTest.java

示例2: process

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
public void process(Exchange exchange) throws Exception {
    PublishRequest request = new PublishRequest();

    request.setTopicArn(getConfiguration().getTopicArn());
    request.setSubject(determineSubject(exchange));
    request.setMessageStructure(determineMessageStructure(exchange));
    request.setMessage(exchange.getIn().getBody(String.class));

    LOG.trace("Sending request [{}] from exchange [{}]...", request, exchange);
    
    PublishResult result = getEndpoint().getSNSClient().publish(request);

    LOG.trace("Received result [{}]", result);
    
    Message message = getMessageForResponse(exchange);
    message.setHeader(SnsConstants.MESSAGE_ID, result.getMessageId());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SnsProducer.java

示例3: execute

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

示例4: publish

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Override
public PublishResult publish(AwsParamsDto awsParamsDto, String topicArn, String messageText, List<MessageHeader> messageHeaders)
{
    Map<String, MessageAttributeValue> messageAttributes = null;

    if (CollectionUtils.isNotEmpty(messageHeaders))
    {
        messageAttributes = new HashMap<>();

        for (MessageHeader messageHeader : messageHeaders)
        {
            messageAttributes.put(messageHeader.getKey(), new MessageAttributeValue().withDataType("String").withStringValue(messageHeader.getValue()));
        }
    }

    return snsOperations.publish(topicArn, messageText, messageAttributes, awsClientFactory.getAmazonSNSClient(awsParamsDto));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:18,代码来源:SnsDaoImpl.java

示例5: sendPushMessage

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
public PublishResult sendPushMessage(AmazonSNS snsClient, PushPlatform platform, String targetArn, Map<String, Object> customAppMessageMap, Map<String, MessageAttributeValue> messageAttributes) throws IOException {
	Map<String, Object> appMessageMap = new HashMap<String, Object>();

	if (platform == PushPlatform.GCM) {
		appMessageMap.put("collapse_key", "single");
		appMessageMap.put("delay_while_idle", true);
		appMessageMap.put("time_to_live", 30);
		appMessageMap.put("dry_run", false);
	}

	if (customAppMessageMap != null) {
		appMessageMap.putAll(customAppMessageMap);
	}

	String message = ServerUtil.asJson(appMessageMap);

	return sendPushMessage(snsClient, platform, targetArn, message, messageAttributes);
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:19,代码来源:PushSnsService.java

示例6: sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttribute

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Test
public void sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttribute() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    ArgumentCaptor<PublishRequest> publishRequestArgumentCaptor = ArgumentCaptor.forClass(PublishRequest.class);
    when(amazonSns.publish(publishRequestArgumentCaptor.capture())).thenReturn(new PublishResult());

    String headerValue = "Header value";
    String headerName = "MyHeader";
    Message<String> message = MessageBuilder.withPayload("Hello").setHeader(headerName, headerValue).build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(headerValue, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getStringValue());
    assertEquals(MessageAttributeDataTypes.STRING, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getDataType());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:TopicMessageChannelTest.java

示例7: sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Test
public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    ArgumentCaptor<PublishRequest> publishRequestArgumentCaptor = ArgumentCaptor.forClass(PublishRequest.class);
    when(amazonSns.publish(publishRequestArgumentCaptor.capture())).thenReturn(new PublishResult());

    ByteBuffer headerValue = ByteBuffer.wrap("My binary data!".getBytes());
    String headerName = "MyHeader";
    Message<String> message = MessageBuilder.withPayload("Hello").setHeader(headerName, headerValue).build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(headerValue, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getBinaryValue());
    assertEquals(MessageAttributeDataTypes.BINARY, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getDataType());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:TopicMessageChannelTest.java

示例8: sendMessage_withUuidAsId_shouldConvertUuidToString

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Test
public void sendMessage_withUuidAsId_shouldConvertUuidToString() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    TopicMessageChannel messageChannel = new TopicMessageChannel(amazonSns, "http://testQueue");
    Message<String> message = MessageBuilder.withPayload("Hello").build();
    UUID uuid = (UUID) message.getHeaders().get(MessageHeaders.ID);

    ArgumentCaptor<PublishRequest> sendMessageRequestArgumentCaptor = ArgumentCaptor.forClass(PublishRequest.class);
    when(amazonSns.publish(sendMessageRequestArgumentCaptor.capture())).thenReturn(new PublishResult());

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(uuid.toString(), sendMessageRequestArgumentCaptor.getValue().getMessageAttributes().get(MessageHeaders.ID).getStringValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:TopicMessageChannelTest.java

示例9: publish

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Override
public PublishResult publish(PublishRequest publishRequest) throws AmazonClientException {
    String topicArn = publishRequest.getTopicArn();
    if (!_subscriptionsForTopic.containsKey(topicArn)) {
        throw new NotFoundException("no such topic " + topicArn);
    }
    List<Subscription> topicSubscriptions = FluentIterable.
            from(_subscriptionsForTopic.get(topicArn)).
            transform(Functions.forMap(_subscriptionsByArn)).
            toList();
    for (Subscription subscription : topicSubscriptions) {
        String queueName = getLast(subscription.getEndpoint().split(":"));
        String queueUrl = _sqsClient.
                getQueueUrl(new GetQueueUrlRequest().withQueueName(queueName)).
                getQueueUrl();
        _sqsClient.sendMessage(new SendMessageRequest().
                withQueueUrl(queueUrl).
                withMessageBody(publishRequest.getMessage()));
    }
    return new PublishResult();
}
 
开发者ID:bazaarvoice,项目名称:awslocal,代码行数:22,代码来源:InMemorySNS.java

示例10: sendNotification

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
public String sendNotification(CFNAssistNotification notification) throws CfnAssistException {
	String topicArn = getTopicARN();
	if (topicArn.isEmpty()) {
		logger.info("Will not send notification as sns topic not found, topic is: " + TOPIC_NAME);
		return "";
	}
	
	ObjectMapper objectMapper = new ObjectMapper();
	try {
		logger.info("Send notification: " + notification);
		String json = objectMapper.writeValueAsString(notification);
		PublishResult result = snsClient.publish(topicArn, json);
		logger.info(String.format("Send message on topic %s with id %s", TOPIC_NAME, result.getMessageId()));
		return result.getMessageId();
	}
	catch (JsonProcessingException jsonException) {
		throw new CfnAssistException("Unable to create notification JSON " + jsonException.toString());
	}
	catch (AuthorizationErrorException authException) {
		logger.error("Did not send SNS notification. You may need to update permissions for user via IAM. Exception was " 
				+ authException);
		return "";
	}
}
 
开发者ID:cartwrightian,项目名称:cfnassist,代码行数:25,代码来源:SNSNotificationSender.java

示例11: executeOutboundOperation

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
/**
 * Executes the outbound Sns Operation.
 * 
 */
public Object executeOutboundOperation(final Message<?> message) {

	try {
		String serializedMessage = messageMarshaller.serialize(message);

		if (snsTestProxy == null) {
			PublishRequest request = new PublishRequest();
			PublishResult result = client.publish(request.withTopicArn(
					topicArn).withMessage(serializedMessage));
			log.debug("Published message to topic: "
					+ result.getMessageId());
		} else {
			snsTestProxy.dispatchMessage(serializedMessage);
		}

	} catch (MessageMarshallerException e) {
		log.error(e.getMessage(), e);
		throw new MessagingException(e.getMessage(), e.getCause());
	}

	return message.getPayload();
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:27,代码来源:SnsExecutor.java

示例12: demoNotification

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
private void demoNotification(Platform platform, String principal,
        String credential, String platformToken, String applicationName){
    // Create Platform Application. This corresponds to an app on a platform.
    CreatePlatformApplicationResult platformApplicationResult = createPlatformApplication(
            applicationName, platform, principal, credential);
    System.out.println(platformApplicationResult);

    // The Platform Application Arn can be used to uniquely identify the Platform Application.
    String platformApplicationArn = platformApplicationResult.getPlatformApplicationArn();

    // Create an Endpoint. This corresponds to an app on a device.
    CreatePlatformEndpointResult platformEndpointResult = createPlatformEndpoint(
            "CustomData - Useful to store endpoint specific data", platformToken, platformApplicationArn);
    System.out.println(platformEndpointResult);

    // Publish a push notification to an Endpoint.
    PublishResult publishResult = publish(platformEndpointResult.getEndpointArn(), platform);
    System.out.println("Published.  MessageId="+ publishResult.getMessageId());
    // Delete the Platform Application since we will no longer be using it.
    deletePlatformApplication(platformApplicationArn);
}
 
开发者ID:daffodilistic,项目名称:aws-snsmobilepush,代码行数:22,代码来源:SNSMobilePush.java

示例13: publish

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
private PublishResult publish(String endpointArn, Platform platform) {
    PublishRequest publishRequest = new PublishRequest();
    Map<String, String> messageMap = new HashMap<String, String>();
    String message;
    messageMap.put("default", defaultMessage);
    messageMap.put(platform.name(), getPlatformSampleMessage(platform));
    // For direct publish to mobile end points, topicArn is not relevant.
    publishRequest.setTargetArn(endpointArn);
    publishRequest.setMessageStructure("json");
    message = jsonify(messageMap);

    // Display the message that will be sent to the endpoint/
    System.out.println(message);

    publishRequest.setMessage(message);
    return snsClient.publish(publishRequest);
}
 
开发者ID:daffodilistic,项目名称:aws-snsmobilepush,代码行数:18,代码来源:SNSMobilePush.java

示例14: publish

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
public static Future<PublishResult> publish(String topic, String message) {
	String arn = String.format(ARN_TEMPLATE, properties.getProperty("aws.region"),
			properties.getProperty("aws.user.id"), topic);
	LOG.info("Sending SNS publish request to topic: {}", arn);
	PublishRequest publishRequest = new PublishRequest(arn, message);
	return SNS_CLIENT.publishAsync(publishRequest);
}
 
开发者ID:villeau,项目名称:pprxmtr,代码行数:8,代码来源:SNS.java

示例15: testDiscardOldest

import com.amazonaws.services.sns.model.PublishResult; //导入依赖的package包/类
@Test
public void testDiscardOldest() throws Exception
{
    initialize("TestSNSAppender/testDiscardOldest.properties");

    // this is a dummy client: never actually run the writer thread, but
    // need to test the real writer
    MockSNSClient mockClient = new MockSNSClient("example", Arrays.asList("example"))
    {
        @Override
        protected PublishResult publish0(PublishRequest request)
        {
            throw new TestingException("this isn't going to work");
        }
    };

    appender.setThreadFactory(new NullThreadFactory());
    appender.setWriterFactory(mockClient.newWriterFactory());

    for (int ii = 0 ; ii < 20 ; ii++)
    {
        logger.debug("message " + ii);
    }

    List<LogMessage> messages = appender.getMessageQueue().toList();

    assertEquals("number of messages in queue", 10, messages.size());
    assertEquals("oldest message", "message 10\n", messages.get(0).getMessage());
    assertEquals("newest message", "message 19\n", messages.get(9).getMessage());
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:31,代码来源:TestSNSAppender.java


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