User notification playing a very important role in modern application. Basically exist are two types of notifications:
-
trigger - which are triggered based on action of event.
-
bulk - which are triggered after user subscribed for some event.
On production, there are a few important things to think about:
-
Use Supervisor to keep your worker(s) running
-
Don't Let Workers Run Forever
-
Restart Workers on Deploy
To run a new consumer for message processing - use the command with parameter. Where parameter - this is a queue name.
bin/console messenger:consume message sent notsent
Cache usage gives us an available template without load from DB. Thanks for that we save time for loading and transform.
For us each type of message we could have a next priority queue:
-
high - use for message that have a limited time fife (password restore, confirm registration...)
-
medium - use for event or action notification
-
low - use for subscribers notification
When there is no more space in the collection ["sent"], the oldest documents are deleted and new data is added to the end. More detail read here
When storage a sent messages becomes a bottleneck in your architecture, you could to replace repository interface to queue interface and push the data in the next queue ["sent", "notSent"]. I following YAGNI principle and do not stay do it this improvement now.
Params | Example | Description |
---|---|---|
user_id | 74b757bb-79de-44cf-88f4-08ce874bd374 | user who needs to send an notification |
to | {"email":"[email protected]","phone":"+380938982443"} | sent type for recipient and contact data |
template | {"name":"welcome","lang":"en","variables":["Roman"]} | sent template with require params |
Path | Method | Scheme | Grant |
---|---|---|---|
/api/admin/templates | POST | ANY | ALL |
/api/admin/templates | GET | ANY | ALL |
/api/admin/templates/{id} | GET | ANY | ALL |
/api/admin/templates/{id} | PUT | ANY | ALL |
/api/admin/templates/{id} | DELETE | ANY | ALL |
Add docker machine IP to /etc/hosts:
127.0.0.1 admin.test
- PHP 7.4
- Symfony 5.0
- RabbitMQ 3.7
- MongoDB 4.2
MongoDB open https://localhost:8081 and use login and password:
user: root
password: secret
RabitMQ open https://localhost:15672 and use login and password:
user: rabbitmq
password: rabbitmq
make pre-commit
Email Sending Architecture Using Messaging Queue
Sending sms reminders with symfony
Dykyi Roman, e-mail: [email protected]