private string GetJsonFromS3Pointer(MessageS3Pointer s3Pointer)
 {
     try
     {
         return(JsonConvert.SerializeObject(s3Pointer));
     }
     catch (Exception e)
     {
         throw new AmazonClientException("Failed to convert S3 object pointer to text. Message was not sent.", e);
     }
 }
Example #2
0
        private SendMessageRequest StoreMessageInS3(SendMessageRequest sendMessageRequest)
        {
            CheckMessageAttributes(sendMessageRequest.MessageAttributes);

            var s3Key              = clientConfiguration.Is3KeyProvider.GenerateName();
            var messageContentStr  = sendMessageRequest.MessageBody;
            var messageContentSize = Encoding.UTF8.GetBytes(messageContentStr).LongCount();

            var messageAttributeValue = new MessageAttributeValue {
                DataType = "Number", StringValue = messageContentSize.ToString()
            };

            sendMessageRequest.MessageAttributes.Add(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);
            var s3Pointer = new MessageS3Pointer(clientConfiguration.S3BucketName, s3Key);

            StoreTextInS3(s3Key, messageContentStr);

            sendMessageRequest.MessageBody = GetJsonFromS3Pointer(s3Pointer);

            return(sendMessageRequest);
        }
        private async Task <SendMessageRequest> StoreMessageInS3Async(SendMessageRequest sendMessageRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            CheckMessageAttributes(sendMessageRequest.MessageAttributes);

            var s3Key              = clientConfiguration.Is3KeyProvider.GenerateName();
            var messageContentStr  = sendMessageRequest.MessageBody;
            var messageContentSize = Encoding.UTF8.GetBytes(messageContentStr).LongCount();

            var messageAttributeValue = new MessageAttributeValue {
                DataType = "Number", StringValue = messageContentSize.ToString()
            };

            sendMessageRequest.MessageAttributes.Add(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME, messageAttributeValue);
            var s3Pointer = new MessageS3Pointer(clientConfiguration.S3BucketName, s3Key);

            await StoreTextInS3Async(s3Key, messageContentStr, cancellationToken).ConfigureAwait(false);

            sendMessageRequest.MessageBody = GetJsonFromS3Pointer(s3Pointer);

            return(sendMessageRequest);
        }