Search code examples
node.jsmessage-queuenodemailerloopback

Sending email through Redis Simple Message Queue


I have to send email to 10 users in my app but I have to send them email separately . I am using loopback framework and for sending email and rsmq library

I have two approaches in mind for sending email

Approach 1

I should pass an array of emails to one message in the queue producer and in the queue listener I should iterate that array of email and send email one by one

Approach 2

I should pass separate message in the queue producer for every user to send email

Which approach is better and why ?


Solution

  • In Message Queuing, it is good to send one processable entry as one message to queue.

    Reason Why:

    • In case you split the email sender into muliple functions, say for example after sending email, you need to update some log, update email count or anything (other example may suit well to explain), then every email needs to be proceeded independently by different functions.

    Reason Why Not:

    • In case of batch processing, you may need to maintain no of emails per message and it exceed you need to write logic to split into batchee

    • Failure in processing of one message in middle may fail sending the rest of emails in same message.