Search in sources :

Example 1 with SendMessageRequest

use of com.amazonaws.services.sqs.model.SendMessageRequest in project camel by apache.

the class SqsProducer method process.

public void process(Exchange exchange) throws Exception {
    String body = exchange.getIn().getBody(String.class);
    SendMessageRequest request = new SendMessageRequest(getQueueUrl(), body);
    request.setMessageAttributes(translateAttributes(exchange.getIn().getHeaders(), exchange));
    addDelay(request, exchange);
    LOG.trace("Sending request [{}] from exchange [{}]...", request, exchange);
    SendMessageResult result = getClient().sendMessage(request);
    LOG.trace("Received result [{}]", result);
    Message message = getMessageForResponse(exchange);
    message.setHeader(SqsConstants.MESSAGE_ID, result.getMessageId());
    message.setHeader(SqsConstants.MD5_OF_BODY, result.getMD5OfMessageBody());
}
Also used : Message(org.apache.camel.Message) SendMessageResult(com.amazonaws.services.sqs.model.SendMessageResult) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest)

Example 2 with SendMessageRequest

use of com.amazonaws.services.sqs.model.SendMessageRequest in project aws-doc-sdk-examples by awsdocs.

the class SendReceiveMessages method main.

public static void main(String[] args) {
    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
    try {
        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());
    }
}
Also used : SendMessageBatchRequest(com.amazonaws.services.sqs.model.SendMessageBatchRequest) Message(com.amazonaws.services.sqs.model.Message) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) SendMessageBatchRequestEntry(com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry) AmazonSQSException(com.amazonaws.services.sqs.model.AmazonSQSException) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest)

Aggregations

SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)2 AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)1 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)1 CreateQueueResult (com.amazonaws.services.sqs.model.CreateQueueResult)1 Message (com.amazonaws.services.sqs.model.Message)1 SendMessageBatchRequest (com.amazonaws.services.sqs.model.SendMessageBatchRequest)1 SendMessageBatchRequestEntry (com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry)1 SendMessageResult (com.amazonaws.services.sqs.model.SendMessageResult)1 Message (org.apache.camel.Message)1