A
A
Artem2019-02-05 10:23:52
PHP
Artem, 2019-02-05 10:23:52

Is the chat implementation correct?

The topic is certainly beaten, but I still wanted to ask if the idea is correct according to the logic of work.
1. the site is made in php (yii2)
2. the request to send a message goes ajax to php. On the backend, we check that the user is ours and send a message to redis (publish) and to the rabbitmq queue manager (to send to the database).
3. NodeJS listens to radish events and socket.io then sends messages to users in rooms.
4. on the front, socket.io notifies you of new messages.
Of course, I will test for loads, but I really want to hear your opinion.
Thank you!
----
Solution:
In general, here's how it all worked.
On the client, socket.io establishes a connection with nodejs passing jsonwebtoken and user data. Create a room whose name is the user id.
I made a chat on vue to simplify support.
When sending a message for ajax requests to php, we send a message to nodejs via redis and put it in rabbitmq for further recording in the database.
Nodejs listens to the radish channel - receives a message that has a list of chat users and sends it to the rooms (and the room name is the user id)
At the front, using socket.io, we listen to incoming messages, and if this is a chat page, we sort the dialogue messages and chat lists.
If this is not a dialog page, then we show a popup.
---
Load testing not done yet.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lander, 2019-02-05
@usdglander

Chat on ajax - it seems to me not the best solution. It might be better to use web sockets.

S
Sergey S., 2019-02-05
@seganim

Chat via PHP is of course a working option, but not the most adequate. Use websockets.

V
Vitaliy_P, 2019-02-05
@Vitaliy_P

If you already have a ready-made site in php, and the chat functionality is more of an addition to it, it seems to me that it is a completely normal implementation in this case.
If, however, the essence of the project consists only of a chat, then for such things closer (does not mean must have) node.js for the backend API + some kind of react or vue.js on the frontend + websockets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question