Closed joao-vitor-felix closed 1 week ago
if i'm understanding right it looks like you're doing Records[0]
- the messages are sometimes batched you have to iterate over all of them
if i'm understanding right it looks like you're doing
Records[0]
- the messages are sometimes batched you have to iterate over all of them
Thank you for your answer (and fast answer, hahaha)! It actually makes sense, I'll try it and I'll come back here to let you know if it works
@thdxr Hey, it seems like that's what was happening to me, I'll leave a pic down below.
I don't know why, but apparently, when I send many messages, sometimes it puts them all together into one single array instead of one message per time, some of them were send into a single array, though.
I didn't know that, is it a default AWS behavior? I mean batch them into one single array when it comes to many messages being sent? Do you know where I can read more about it?
Anyway, it seems like it'll solve my problem, I'll let you know if something goes wrong, but I don't think it will.
Once again, thank you!
Here's my final code for the queue:
import { SQSHandler } from 'aws-lambda'
import axios from 'axios'
import {
SendWhatsAppMessageRequestedSchema,
sendWhatsAppMessageRequestedSchema,
} from './schema'
export const handler: SQSHandler = async (event) => {
const messages: SendWhatsAppMessageRequestedSchema[] = event.Records.map(
(record) => JSON.parse(record.body)
)
console.info('Send WhatsApp Message Requested:', messages)
for (const message of messages) {
try {
sendWhatsAppMessageRequestedSchema.parse(message)
await axios.post(message.url, {
...message.body,
})
console.info('WhatsApp message sent to:', message.body.telefone)
} catch (error) {
console.error('Error processing message:', message, error)
}
}
}
EDIT: Found an explanation about batching behavior here, thank you, Dax!
Hey! I'm going through a problem and I'm putting it out to see if someone can help me.
Before anything, the sst's version on this project is
0.1.21
. I'll show you some logs down below, and I've switched sensitive data to dummy data.So I have a cron job called
NotifyComingUpBills
.Here's a piece of the code inside this cron job, it basically fetches users with bills expiring on the determined day and sends a message to them.
notifyExpiredTransactions
is just a slight variation ofnotifyComingUpTransactions
. I'll show you the queue I'm calling inside the cron job. This queue just sends a message to someone through WhatsApp.Here are the logs from the cron job execution on 09/04.
So you can see that it logs the notified info, which means it sends to the WhatsApp queue, here's the logs from WhatsApp queue between 09/03 and 09/05 (Notice that there are only 2 executions from 09/04).
Here are both
SendWhatsAppMessageRequested
executions from 09/04I called it
SendWhatsAppMessageRequested
5 times inside my cron job on 09/04, but only 2 messages have arrived on the actual queue, and there are no error logs or anything, it has just disappeared.To finish it, I'll let you know how the queue is being created (I've omitted all queues but
SendWhatsAppMessageRequested
just to demonstrate it).If you need further information, let me know! This issue is happening in production and I would appreciate your help!