1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-08 06:06:40 +02:00

Check maximum allowed size of sqs message and send smaller portion of it, when size is exceeded

This commit is contained in:
Honza Machala
2017-07-25 01:09:16 +02:00
parent 7b99283627
commit 548309c2c1

View File

@@ -21,6 +21,12 @@ use Monolog\Logger;
*/
class SqsHandler extends AbstractProcessingHandler
{
/** 256 KB in bytes - maximum message size in SQS */
const MAX_MESSAGE_SIZE = 262144;
/** 100 KB in bytes - head message size for new error log */
const HEAD_MESSAGE_SIZE = 102400;
/** @var SqsClient */
private $client;
/** @var string */
@@ -45,9 +51,14 @@ class SqsHandler extends AbstractProcessingHandler
throw new \InvalidArgumentException('SqsHandler accepts only formatted records as a string');
}
$messageBody = $record['formatted'];
if (strlen($messageBody) >= self::MAX_MESSAGE_SIZE) {
$messageBody = substr($messageBody, 0, self::HEAD_MESSAGE_SIZE);
}
$this->client->sendMessage([
'QueueUrl' => $this->queueUrl,
'MessageBody' => $record['formatted'],
'MessageBody' => $messageBody,
]);
}
}