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

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

Introduction

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

Prototype

public SendMessageRequest() 

Source Link

Document

Default constructor for SendMessageRequest object.

Usage

From source file:aws.example.sqs.SendReceiveMessages.java

License:Open Source License

public static void main(String[] args) {
    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    try {//from   w  ww.j av  a  2s  .  c o m
        CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }

    String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();

    SendMessageRequest send_msg_request = new SendMessageRequest().withQueueUrl(queueUrl)
            .withMessageBody("hello world").withDelaySeconds(5);
    sqs.sendMessage(send_msg_request);

    // Send multiple messages to the queue
    SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest().withQueueUrl(queueUrl)
            .withEntries(new SendMessageBatchRequestEntry("msg_1", "Hello from message 1"),
                    new SendMessageBatchRequestEntry("msg_2", "Hello from message 2").withDelaySeconds(10));
    sqs.sendMessageBatch(send_batch_request);

    // receive messages from the queue
    List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();

    // delete messages from the queue
    for (Message m : messages) {
        sqs.deleteMessage(queueUrl, m.getReceiptHandle());
    }
}

From source file:awslabs.lab31.SolutionCode.java

License:Open Source License

@Override
public void postToQueue(AmazonSQSClient sqsClient, String queueUrl, String messageText) {
    // TODO: Construct a SendMessageRequest object using the provided queue URL and message.
    SendMessageRequest sendMessageRequest = new SendMessageRequest().withMessageBody(messageText)
            .withQueueUrl(queueUrl);/*from  w w  w  .j a v a  2  s .c o  m*/

    // TODO: Submit the request using the sendMessage method of the sqsClient object.
    sqsClient.sendMessage(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  a  v  a2 s .  co 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.netflix.suro.sink.notice.SQSNotice.java

License:Apache License

@Override
public boolean send(String message) {
    boolean sent = false;

    try {/*from   w w  w  .  ja  v a2  s  .c  o m*/
        for (String queueUrl : queueUrls) {
            SendMessageRequest request = new SendMessageRequest().withQueueUrl(queueUrl);

            if (enableBase64Encoding) {
                request = request
                        .withMessageBody(new String(Base64.encodeBase64(message.getBytes(Charsets.UTF_8))));
            } else {
                request = request.withMessageBody(message);
            }
            sqsClient.sendMessage(request);
            log.info("SQSNotice: " + message + " sent to " + queueUrl);
            if (!sent) {
                sentMessageCount.incrementAndGet();
                sent = true;
            }
        }
    } catch (Exception e) {
        log.error("Exception while sending SQS notice: " + e.getMessage(), e);
    }

    if (!sent) {
        lostMessageCount.incrementAndGet();
    }

    return sent;
}

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

License:Open Source License

/**
 * Send an event message to SQS./*from   ww w.  jav  a2s  . c  om*/
 * 
 * @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 {//ww  w .j a va 2  s.  c o m
        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);
    }

}

From source file:org.finra.herd.dao.impl.SqsOperationsImpl.java

License:Apache License

@Override
public SendMessageResult sendMessage(String queueName, String messageText,
        Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS) {
    try {/*from  w  ww.j ava  2 s.co m*/
        return amazonSQS.sendMessage(
                new SendMessageRequest().withQueueUrl(amazonSQS.getQueueUrl(queueName).getQueueUrl())
                        .withMessageBody(messageText).withMessageAttributes(messageAttributes));
    } catch (QueueDoesNotExistException e) {
        throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName),
                e);
    }
}

From source file:org.thingsboard.rule.engine.aws.sqs.TbSqsNode.java

License:Apache License

private TbMsg publishMessage(TbContext ctx, TbMsg msg) {
    String queueUrl = TbNodeUtils.processPattern(this.config.getQueueUrlPattern(), msg.getMetaData());
    SendMessageRequest sendMsgRequest = new SendMessageRequest();
    sendMsgRequest.withQueueUrl(queueUrl);
    sendMsgRequest.withMessageBody(msg.getData());
    Map<String, MessageAttributeValue> messageAttributes = new HashMap<>();
    this.config.getMessageAttributes().forEach((k, v) -> {
        String name = TbNodeUtils.processPattern(k, msg.getMetaData());
        String val = TbNodeUtils.processPattern(v, msg.getMetaData());
        messageAttributes.put(name, new MessageAttributeValue().withDataType("String").withStringValue(val));
    });//from   w w w .j a  va2 s .  co  m
    sendMsgRequest.setMessageAttributes(messageAttributes);
    if (this.config.getQueueType() == TbSqsNodeConfiguration.QueueType.STANDARD) {
        sendMsgRequest.withDelaySeconds(this.config.getDelaySeconds());
    } else {
        sendMsgRequest.withMessageDeduplicationId(msg.getId().toString());
        sendMsgRequest.withMessageGroupId(msg.getOriginator().toString());
    }
    SendMessageResult result = this.sqsClient.sendMessage(sendMsgRequest);
    return processSendMessageResult(ctx, msg, result);
}

From source file:org.thingsboard.server.extensions.sqs.plugin.SqsMessageHandler.java

License:Apache License

private void sendMessageToStandardQueue(PluginContext ctx, TenantId tenantId, RuleId ruleId,
        RuleToPluginMsg<?> msg) {/*from   w  w  w  .jav a2  s . c om*/
    SqsStandardQueueActionPayload payload = ((SqsStandardQueueActionMsg) msg).getPayload();
    SendMessageRequest sendMsgRequest = new SendMessageRequest().withDelaySeconds(payload.getDelaySeconds())
            .withQueueUrl(payload.getQueue()).withMessageBody(payload.getMsgBody());
    sqs.sendMessage(sendMsgRequest);
    if (payload.isSync()) {
        ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId,
                BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId())));
    }
}

From source file:org.thingsboard.server.extensions.sqs.plugin.SqsMessageHandler.java

License:Apache License

private void sendMessageToFifoQueue(PluginContext ctx, TenantId tenantId, RuleId ruleId,
        RuleToPluginMsg<?> msg) {/* w  ww. j av  a 2  s .co  m*/
    SqsFifoQueueActionPayload payload = ((SqsFifoQueueActionMsg) msg).getPayload();
    SendMessageRequest sendMsgRequest = new SendMessageRequest().withQueueUrl(payload.getQueue())
            .withMessageBody(payload.getMsgBody()).withMessageGroupId(payload.getDeviceId());
    sqs.sendMessage(sendMsgRequest);
    if (payload.isSync()) {
        ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId,
                BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId())));
    }
}