use of com.amazonaws.services.sqs.model.SendMessageBatchResult in project spring-integration-aws by spring-projects.
the class SqsMessageHandler method handleMessageToAws.
@Override
@SuppressWarnings("unchecked")
protected Future<?> handleMessageToAws(Message<?> message) {
Object payload = message.getPayload();
if (payload instanceof SendMessageBatchRequest) {
AsyncHandler<SendMessageBatchRequest, SendMessageBatchResult> asyncHandler = obtainAsyncHandler(message, (SendMessageBatchRequest) payload);
return this.amazonSqs.sendMessageBatchAsync((SendMessageBatchRequest) payload, asyncHandler);
}
SendMessageRequest sendMessageRequest;
if (payload instanceof SendMessageRequest) {
sendMessageRequest = (SendMessageRequest) payload;
} else {
String queue = message.getHeaders().get(AwsHeaders.QUEUE, String.class);
if (!StringUtils.hasText(queue) && this.queueExpression != null) {
queue = this.queueExpression.getValue(getEvaluationContext(), message, String.class);
}
Assert.state(queue != null, "'queue' must not be null for sending an SQS message. " + "Consider configuring this handler with a 'queue'( or 'queueExpression') or supply an " + "'aws_queue' message header");
String queueUrl = (String) this.destinationResolver.resolveDestination(queue);
String messageBody = (String) this.messageConverter.fromMessage(message, String.class);
sendMessageRequest = new SendMessageRequest(queueUrl, messageBody);
if (this.delayExpression != null) {
Integer delay = this.delayExpression.getValue(getEvaluationContext(), message, Integer.class);
sendMessageRequest.setDelaySeconds(delay);
}
if (this.messageGroupIdExpression != null) {
String messageGroupId = this.messageGroupIdExpression.getValue(getEvaluationContext(), message, String.class);
sendMessageRequest.setMessageGroupId(messageGroupId);
}
if (this.messageDeduplicationIdExpression != null) {
String messageDeduplicationId = this.messageDeduplicationIdExpression.getValue(getEvaluationContext(), message, String.class);
sendMessageRequest.setMessageDeduplicationId(messageDeduplicationId);
}
HeaderMapper<Map<String, MessageAttributeValue>> headerMapper = getHeaderMapper();
if (headerMapper != null) {
mapHeaders(message, sendMessageRequest, headerMapper);
}
}
AsyncHandler<SendMessageRequest, SendMessageResult> asyncHandler = obtainAsyncHandler(message, sendMessageRequest);
return this.amazonSqs.sendMessageAsync(sendMessageRequest, asyncHandler);
}
use of com.amazonaws.services.sqs.model.SendMessageBatchResult in project aws-sdk-android by aws-amplify.
the class MessageMD5ChecksumHandler method afterResponse.
@Override
public void afterResponse(Request<?> request, Object response, TimingInfo timingInfo) {
if (request != null && response != null) {
// SendMessage
if (request.getOriginalRequest() instanceof SendMessageRequest && response instanceof SendMessageResult) {
SendMessageRequest sendMessageRequest = (SendMessageRequest) request.getOriginalRequest();
SendMessageResult sendMessageResult = (SendMessageResult) response;
sendMessageOperationMd5Check(sendMessageRequest, sendMessageResult);
} else // ReceiveMessage
if (request.getOriginalRequest() instanceof ReceiveMessageRequest && response instanceof ReceiveMessageResult) {
ReceiveMessageResult receiveMessageResult = (ReceiveMessageResult) response;
receiveMessageResultMd5Check(receiveMessageResult);
} else // SendMessageBatch
if (request.getOriginalRequest() instanceof SendMessageBatchRequest && response instanceof SendMessageBatchResult) {
SendMessageBatchRequest sendMessageBatchRequest = (SendMessageBatchRequest) request.getOriginalRequest();
SendMessageBatchResult sendMessageBatchResult = (SendMessageBatchResult) response;
sendMessageBatchOperationMd5Check(sendMessageBatchRequest, sendMessageBatchResult);
}
}
}
use of com.amazonaws.services.sqs.model.SendMessageBatchResult in project nifi by apache.
the class TestPutSQS method testSimplePut.
@Test
public void testSimplePut() throws IOException {
runner.setValidateExpressionUsage(false);
runner.setProperty(PutSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000");
Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid());
final Map<String, String> attrs = new HashMap<>();
attrs.put("filename", "1.txt");
runner.enqueue("TestMessageBody", attrs);
SendMessageBatchResult batchResult = new SendMessageBatchResult();
Mockito.when(mockSQSClient.sendMessageBatch(Mockito.any(SendMessageBatchRequest.class))).thenReturn(batchResult);
runner.run(1);
ArgumentCaptor<SendMessageBatchRequest> captureRequest = ArgumentCaptor.forClass(SendMessageBatchRequest.class);
Mockito.verify(mockSQSClient, Mockito.times(1)).sendMessageBatch(captureRequest.capture());
SendMessageBatchRequest request = captureRequest.getValue();
assertEquals("https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000", request.getQueueUrl());
assertEquals("hello", request.getEntries().get(0).getMessageAttributes().get("x-custom-prop").getStringValue());
assertEquals("TestMessageBody", request.getEntries().get(0).getMessageBody());
runner.assertAllFlowFilesTransferred(PutSQS.REL_SUCCESS, 1);
}
use of com.amazonaws.services.sqs.model.SendMessageBatchResult in project conductor by Netflix.
the class SQSObservableQueue method publishMessages.
private void publishMessages(List<Message> messages) {
logger.debug("Sending {} messages to the SQS queue: {}", messages.size(), queueName);
SendMessageBatchRequest batch = new SendMessageBatchRequest(queueURL);
messages.forEach(msg -> {
SendMessageBatchRequestEntry sendr = new SendMessageBatchRequestEntry(msg.getId(), msg.getPayload());
batch.getEntries().add(sendr);
});
logger.debug("sending {} messages in batch", batch.getEntries().size());
SendMessageBatchResult result = client.sendMessageBatch(batch);
logger.debug("send result: {} for SQS queue: {}", result.getFailed().toString(), queueName);
}
Aggregations