本文整理汇总了Java中com.amazonaws.services.sns.model.PublishRequest.setMessageStructure方法的典型用法代码示例。如果您正苦于以下问题:Java PublishRequest.setMessageStructure方法的具体用法?Java PublishRequest.setMessageStructure怎么用?Java PublishRequest.setMessageStructure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.sns.model.PublishRequest
的用法示例。
在下文中一共展示了PublishRequest.setMessageStructure方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的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());
}
示例2: execute
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的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());
}
示例3: sendPushMessage
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的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;
}
示例4: publish
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的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);
}
示例5: publish
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的package包/类
private PublishResult publish(String endpointArn, Platform platform,
Map<Platform, Map<String, MessageAttributeValue>> attributesMap) {
PublishRequest publishRequest = new PublishRequest();
Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes(attributesMap
.get(platform));
if (notificationAttributes != null && !notificationAttributes.isEmpty()) {
publishRequest.setMessageAttributes(notificationAttributes);
}
publishRequest.setMessageStructure("json");
// If the message attributes are not set in the requisite method,
// notification is sent with default attributes
String message = getPlatformSampleMessage(platform);
Map<String, String> messageMap = new HashMap<String, String>();
messageMap.put(platform.name(), message);
message = SampleMessageGenerator.jsonify(messageMap);
// For direct publish to mobile end points, topicArn is not relevant.
publishRequest.setTargetArn(endpointArn);
// Display the message that will be sent to the endpoint/
System.out.println("{Message Body: " + message + "}");
StringBuilder builder = new StringBuilder();
builder.append("{Message Attributes: ");
for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes
.entrySet()) {
builder.append("(\"" + entry.getKey() + "\": \""
+ entry.getValue().getStringValue() + "\"),");
}
builder.deleteCharAt(builder.length() - 1);
builder.append("}");
System.out.println(builder.toString());
publishRequest.setMessage(message);
return snsClient.publish(publishRequest);
}
示例6: publish
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的package包/类
private PublishResult publish(String endpointArn, Platform platform,
Map<Platform, Map<String, MessageAttributeValue>> attributesMap) {
PublishRequest publishRequest = new PublishRequest();
Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes(attributesMap
.get(platform));
if (notificationAttributes != null && !notificationAttributes.isEmpty()) {
//publishRequest.setMessageAttributes(notificationAttributes);
}
publishRequest.setMessageStructure("json");
// If the message attributes are not set in the requisite method,
// notification is sent with default attributes
String message = getPlatformSampleMessage(platform);
Map<String, String> messageMap = new HashMap<String, String>();
messageMap.put(platform.name(), message);
message = SampleMessageGenerator.jsonify(messageMap);
// For direct publish to mobile end points, topicArn is not relevant.
publishRequest.setTargetArn(endpointArn);
// Display the message that will be sent to the endpoint/
System.out.println("{Message Body: " + message + "}");
StringBuilder builder = new StringBuilder();
builder.append("{Message Attributes: ");
for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes
.entrySet()) {
builder.append("(\"" + entry.getKey() + "\": \""
+ entry.getValue().getStringValue() + "\"),");
}
builder.deleteCharAt(builder.length() - 1);
builder.append("}");
System.out.println(builder.toString());
publishRequest.setMessage(message);
return snsClient.publish(publishRequest);
}
示例7: publishToSnsTopic
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的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();
}
}
示例8: publish
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的package包/类
private PublishResult publish(String endpointArn, Platform platform,
Map<Platform, Map<String, MessageAttributeValue>> attributesMap, String message) {
PublishRequest publishRequest = new PublishRequest();
Map<String, MessageAttributeValue> notificationAttributes = getValidNotificationAttributes(attributesMap
.get(platform));
if (notificationAttributes != null && !notificationAttributes.isEmpty()) {
// TODO: link to updated SNS lib
// publishRequest.setMessageAttributes(notificationAttributes);
}
publishRequest.setMessageStructure("json");
// If the message attributes are not set in the requisite method,
// notification is sent with default attributes
if(message == null)
message = getPlatformStarterMessage(platform);
Map<String, String> messageMap = new HashMap<String, String>();
messageMap.put(platform.name(), message);
message = NotificationMessageGenerator.jsonify(messageMap);
// For direct publish to mobile end points, topicArn is not relevant.
publishRequest.setTargetArn(endpointArn);
// Display the message that will be sent to the endpoint/
System.out.println("{Message Body: " + message + "}");
StringBuilder builder = new StringBuilder();
builder.append("{Message Attributes: ");
for (Map.Entry<String, MessageAttributeValue> entry : notificationAttributes
.entrySet()) {
builder.append("(\"" + entry.getKey() + "\": \""
+ entry.getValue().getStringValue() + "\"),");
}
builder.deleteCharAt(builder.length() - 1);
builder.append("}");
System.out.println(builder.toString());
publishRequest.setMessage(message);
return snsClient.publish(publishRequest);
}
示例9: process
import com.amazonaws.services.sns.model.PublishRequest; //导入方法依赖的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());
}