本文整理汇总了Java中com.amazonaws.services.sqs.model.SendMessageRequest.setMessageBody方法的典型用法代码示例。如果您正苦于以下问题:Java SendMessageRequest.setMessageBody方法的具体用法?Java SendMessageRequest.setMessageBody怎么用?Java SendMessageRequest.setMessageBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.sqs.model.SendMessageRequest
的用法示例。
在下文中一共展示了SendMessageRequest.setMessageBody方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createQueueMessage
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入方法依赖的package包/类
SendMessageResult createQueueMessage(ImageCreateRequest request, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = request.getQueueName();
final String sqsEndpoint = request.getSqsEndpoint();
if (queueName == null || sqsEndpoint == null) {
logger.log("skip create queue. [" + request + "]");
return null;
}
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
request.setSendMessageTimeMillis(System.currentTimeMillis());
try {
CreateQueueRequest req = new CreateQueueRequest(queueName);
String queueUrl = client.createQueue(req).getQueueUrl();
SendMessageRequest sendMessage = new SendMessageRequest();
sendMessage.setQueueUrl(queueUrl);
ObjectMapper om = new ObjectMapper();
sendMessage.setMessageBody(om.writeValueAsString(request));
Future<SendMessageResult> result = client.sendMessageAsync(sendMessage);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error occured in the create queue request.", e);
} finally {
client.shutdown();
}
}
示例2: createQueueMessage
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入方法依赖的package包/类
SendMessageResult createQueueMessage(InstanceRequest instanceRequest, Context context) {
LambdaLogger logger = context.getLogger();
final String queueName = instanceRequest.getQueueName();
final String sqsEndpoint = instanceRequest.getSqsEndpoint();
if (queueName == null || sqsEndpoint == null) {
logger.log("skip create queue. instanceRequest[" + instanceRequest + "]");
return null;
}
AmazonSQSAsync client = createSQSClient();
client.setEndpoint(sqsEndpoint);
try {
CreateQueueRequest req = new CreateQueueRequest(queueName);
String queueUrl = client.createQueue(req).getQueueUrl();
instanceRequest.setSendMessageTimeMillis(System.currentTimeMillis());
SendMessageRequest sendMessage = new SendMessageRequest();
sendMessage.setQueueUrl(queueUrl);
ObjectMapper om = new ObjectMapper();
sendMessage.setMessageBody(om.writeValueAsString(instanceRequest));
Future<SendMessageResult> result = client.sendMessageAsync(sendMessage);
while (!result.isDone()) {
Thread.sleep(100);
}
return result.get();
} catch (Exception e) {
throw new RuntimeException("unexpected error occured in the create queue request.", e);
} finally {
client.shutdown();
}
}
示例3: storeMessageInS3
import com.amazonaws.services.sqs.model.SendMessageRequest; //导入方法依赖的package包/类
private SendMessageRequest storeMessageInS3(SendMessageRequest sendMessageRequest) {
checkMessageAttributes(sendMessageRequest.getMessageAttributes());
String s3Key = UUID.randomUUID().toString();
// Read the content of the message from message body
String messageContentStr = sendMessageRequest.getMessageBody();
Long messageContentSize = getStringSizeInBytes(messageContentStr);
// Add a new message attribute as a flag
MessageAttributeValue messageAttributeValue = new MessageAttributeValue();
messageAttributeValue.setDataType("Number");
messageAttributeValue.setStringValue(messageContentSize.toString());
sendMessageRequest.addMessageAttributesEntry(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME,
messageAttributeValue);
// Store the message content in S3.
storeTextInS3(s3Key, messageContentStr, messageContentSize);
LOG.info("S3 object created, Bucket name: " + clientConfiguration.getS3BucketName() + ", Object key: " + s3Key
+ ".");
// Convert S3 pointer (bucket name, key, etc) to JSON string
MessageS3Pointer s3Pointer = new MessageS3Pointer(clientConfiguration.getS3BucketName(), s3Key);
String s3PointerStr = getJSONFromS3Pointer(s3Pointer);
// Storing S3 pointer in the message body.
sendMessageRequest.setMessageBody(s3PointerStr);
return sendMessageRequest;
}