本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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));
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例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 "";
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}