📜 ⬆️ ⬇️

Open source Java online chat server



Online chat rooms (or online consultants) are on many sites today. Someone actively uses them, someone hates it, and someone sometimes opens a joke for the sake of. For those who want to deploy their own chat server, I’ll tell you about the open source Live Chat Engine solution.


Opportunities


The project contains the minimum required set for working with chats from the user and operator:
- chat itself;
- the ability to leave a review when there are no active operators;
- email notification of such reviews;
- several operators for one chat;
- browser notification of operators about new messages;
- view User-Agent and Ip user;
- View the history of chats and reviews.
')
Integration with various messengers yet, alas.

Chat on site:


Operator's Cabinet:


Architecture


Initially, it was decided to divide the project into 3 logical parts:
- front for operators (chat-front-server);
- web api and chat storage (chat-node-server);
- coordinating server (chat-central-server).



This approach allows you to increase the number of accounts by simply adding new server nodes to the system.
Of course, for one site this scheme may be redundant, so in the future you can think about the light assembly of three servers into one.

Modes of operation


The chat engine can be integrated into existing systems (Tool mode), when an administrator starts an account, the front is accessible only to its own operators, and the node is open to the browsers of site users.

Or, you can start the engine as an independent service (SaaS mode), where users get accounts, and for their use a fee is charged monthly at specified rates ... But then, congratulations, you will create another chat service and you will have to compete with an army of similar services, that will not be easy.

Features of the implementation


- Front and node servers run as web applications on the Tomcat web server.
It does not use Spring or EJB: yes, you can write large projects without popular stacks.
I have already talked about this approach . In any case, this project was a home project and I wanted to write many things on my own, so don’t judge for the lack of your favorite frameworks - and everything is fine without them!

- To communicate with the database, MyBatis and another internal query template engine is used.
MyBatis is, without a doubt, very useful for creating intricate queries, but tedious for simple, same-type CRUDs.
Therefore, I wrote a small UniversalQueries template engine that generates queries on the specified data.

For example, here is a description for an INSERT:

public class CreateUser extends CreateRow { public CreateUser(User user) { //   "users" super("users", // ,    //    : , ,   .. new Id(user.id), new Login(user.login), new Email(user.email), new PswHash(user.pswHash), new ActivationStateDate(user.activationStateDate), new ActivationCode(user.activationCode)); } } 

And SELECT with the condition:

 public class GetAllBlockedUsers extends SelectRows<User>{ public GetAllBlockedUsers() { //    users super("users", //    User User.class, //    new UserFields(), //  WHERE new AndCondition( new AccsBlocked(true) )); } } 

Here are various call examples:

 //INSERT universal.update(new CreateUser(user)); //SELECT List<User> users = universal.select(new GetAllBlockedUsers()); //UPDATE -      universal.update(new UpdateUserById(id, new StatusCode(ACTIVATED), new ActivationStateDate(new Date()), new ActivationCode(null))); 

As a result, all complex queries are written in xml MyBatis, all routine ones are written through this template engine.

- The front for operators is written in Js along with jQuery.

Results


The implementation of such a project took about half a year off.
I hope the project will be interesting both from a training and from a practical point of view.

Thank you for your attention and successful development!

[ Link to Github ]

Source: https://habr.com/ru/post/264865/


All Articles