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


Java SendMessageRequest.setMessageBody方法代码示例

本文整理汇总了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();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:38,代码来源:ImageCreateFunction.java

示例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();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:39,代码来源:InstanceOperation.java

示例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;
	}
 
开发者ID:awslabs,项目名称:amazon-sqs-java-extended-client-lib,代码行数:34,代码来源:AmazonSQSExtendedClient.java


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