Example usage for com.amazonaws.services.sqs.model SendMessageRequest setMessageBody

List of usage examples for com.amazonaws.services.sqs.model SendMessageRequest setMessageBody

Introduction

In this page you can find the example usage for com.amazonaws.services.sqs.model SendMessageRequest setMessageBody.

Prototype


public void setMessageBody(String messageBody) 

Source Link

Document

The message to send.

Usage

From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java

License:Open Source License

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);/*from w w  w . j  ava  2s.c o  m*/

    // 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;
}

From source file:com.eucalyptus.portal.SimpleQueueClientManager.java

License:Open Source License

public void sendMessage(final String queueName, final String message) throws Exception {
    try {//from   w  w  w . j ava  2s  . c o  m
        final SendMessageRequest req = new SendMessageRequest();
        req.setQueueUrl(getQueueUrl(queueName));
        req.setDelaySeconds(0);
        req.setMessageBody(message);
        getSimpleQueueClient().sendMessage(req);
    } catch (final AmazonServiceException ex) {
        throw new Exception("Failed to send message due to service error", ex);
    } catch (final AmazonClientException ex) {
        throw new Exception("Failed to send message due to client error", ex);
    }
}

From source file:com.sitewhere.aws.SqsOutboundEventProcessor.java

License:Open Source License

/**
 * Send an event message to SQS./*w w  w .j  av  a 2 s  .  com*/
 * 
 * @param event
 * @throws SiteWhereException
 */
protected void sendSqsMessage(IDeviceEvent event) throws SiteWhereException {
    SendMessageRequest message = new SendMessageRequest();
    message.setMessageBody(MarshalUtils.marshalJsonAsString(event));
    message.setQueueUrl(getQueueUrl());
    SendMessageResult result = getSqs().sendMessage(message);
    LOGGER.debug("Sent SQS message with id: " + result.getMessageId());
}

From source file:org.apache.usergrid.apm.service.MetricsInjestionServiceSQSImpl.java

License:Apache License

public void sendData(String fullAppName, ClientMetricsEnvelope envelope) {
    try {/*  www .j  a  v  a 2s .com*/
        SendMessageRequest sendMessageRequest = new SendMessageRequest();

        sendMessageRequest.setQueueUrl(AWSUtil.formFullQueueUrl(fullAppName));
        //String message = xStream.toXML(envelope);
        String message = objectMapper.writeValueAsString(envelope);
        sendMessageRequest.setMessageBody(message);
        int length = message.getBytes().length;
        log.info("Sending Message of size : " + length);
        this.sqsAsyncClient.sendMessage(sendMessageRequest);
    } catch (AmazonServiceException ce) {
        log.error("Queue does not exisit or is not accessible for AppId " + fullAppName, ce);
    } catch (JsonGenerationException e) {
        // TODO Auto-generated catch block
        log.error("Some Jackson Error: " + fullAppName, e);
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        log.error("Some Jackson Error: " + fullAppName, e);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        log.error("eror", e);
    }

}