简体   繁体   中英

Symfony2 sending push notifications

I am working on REST API for Android app in Symfony2. Recently I implemented sending push notifications via FCM. Everything works fine, the problem is that my implementation sends notifications normally in controller, so client has to wait for sending all notifications to get response from server, what of course leads to performance issues. Could anyone give me a hint, what is the best way how to handle notifications sending, ie in separate thread or some scheduler? I just don't know what are my possibilities. Thanks in advance.

Well, what you are looking for is kind of an asynchronous worker. That can be accomplished through different ways.

The easiest way might be to store all notifications, that need to be send, in some kind of queue like a table in your Database and processing these entries using a command ( https://symfony.com/doc/current/console.html ) which is regularly executed via crontab.

Another way would be to use something like RabbitMQ and writing a custom consumer which sends the notifications. Thats quite straight-forwarded and requires something like supervisord to demonize the consumer-process.

Maybe the CronJob-Way is the best for you. I didn't quite get, whether these Push-Notifications need to rely on the requests send by your clients but generally you should try to encapsulate all logic from controllers into services.

The Symfony-Documentation is always a good entry for these kind of questions and should give you some more detailed examples and hints: https://symfony.com/doc/current/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM