Replies: 2 comments 8 replies
-
somewhat related... what is the best practice for deleting the message from the queue once it's processed? Am I supposed to get the messageId >> create an SQS client >> delete message OR Is there some built-in best practice in bref that i should be following |
Beta Was this translation helpful? Give feedback.
8 replies
-
To answer your first question, this is normal. The lambda function is preparing for the next message, so all the initialization code runs again to be ready for the next invocation. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to use a function to process messages from SQS. I believe I've followed the demo exactly... here is the file that the function is calling:
`<?php
require_once 'vendor/autoload.php';
// This is a PHP file example.
// Replace it with your application.
$logger = new \Bref\Logger\StderrLogger();
$rand = rand(0,100);
$logger->warning("SQS Handler entered {$rand}");
use Bref\Context\Context;
use Bref\Event\Sqs\SqsEvent;
use Bref\Event\Sqs\SqsHandler;
class Handler extends SqsHandler
{
public function handleSqs(SqsEvent $event, Context $context): void
{
foreach ($event->getRecords() as $record) {
// We can retrieve the message body of each record via
->getBody()
$body = $record->getBody();
}
return new Handler();
`
If you look at the logs below, it looks like the code outside the handler is getting called twice. When I log messages from inside the SQS function, it looks like it's only happening once, so that's good. However, I just want to make sure I'm not doing something wrong before starting to build more functionality on top of this.
Beta Was this translation helpful? Give feedback.
All reactions