Database structure
There are many answers on Stack Overflow and many articles on Internet about possible database structure for instant messenger application.Database structure for different types of chat
Some advices regarding to database structure for chat: here and here with nice scheme on the pic
Instant messenger or chat can be divided into 3 categories:
- private messenger
- group chat
- public chat
Here is most typical and simple database structure:

This database schema works fine for private messenger, I use it in Diary messenger.
Can Message Queue Service be used to create a chat?
The answers:
- Message/Queue service provides a way to post a message on queue and then receive that message on other end. If you are planning to have private chat between your users, this will not be a wise solution to implement because you will end up using multiple queue inside your application. Since we have restriction in creating queue (50 per app) this might be bottle neck for your app. Also, this is an offline messaging and not suited for real time chat application. [more]
- you would be better off storing the message in a database and keeping a marker for each user to say what message they last saw. [more]
How to implement WebSocket protocol in Java?
WebSocket implementation with Java
There are good tutorials:
Oracle documentation, Java API for WebSocket
Java EE 7: Building Web Applications with WebSocket, JavaScript and HTML5
WebSocket implementation with Spring (including STOMP)
How to use WebSocket API in Spring
How to work with STOMP and
STOMP is just derived on top of WebSockets.
I have chosen STOMP protocol, because this protocol easy to implement for simple messaging system. Also, Java API for WebSocket (JSR 356) requires to use Java CDI rather than Spring. When you try to inject bean into server endpoint, there is an NPE.
I develop my project with Spring framework, so STOMP was better chose.
About the difference between CDI and Spring:
You need to deploy your project on TomEE or GlassFish server for working with CDI. Simple Tomcat server is plain servlet container, which supports servlet and JSP technology, but not an CDI technology.
spring-messaging moduleSTOMP is just derived on top of WebSockets.
I have chosen STOMP protocol, because this protocol easy to implement for simple messaging system. Also, Java API for WebSocket (JSR 356) requires to use Java CDI rather than Spring. When you try to inject bean into server endpoint, there is an NPE.
"A class annotated by @Component is registered to a spring bean and its instance is managed by spring as a singleton by default. However, a class annotated by @ServerEndpoint is registered to a server-side WebSocket endpoint and every time the corresponding endpoint's WebSocket is connected to the server, its instance is created and managed by JWA implementation. Therefore, you can't use both annotations together.Maybe the simplest workaround is to use CDI instead of Spring. Of course, your server should support CDI."
https://stackoverflow.com/questions/29306854/serverendpoint-and-autowired
I develop my project with Spring framework, so STOMP was better chose.
About the difference between CDI and Spring:
"CDI stands for "context and dependency injection", while Spring is a complete ecosystem around a dependency injection container. To compare both, you have to differentiate the comparison."
https://stackoverflow.com/questions/5973364/is-cdi-a-good-replacement-of-spring
You need to deploy your project on TomEE or GlassFish server for working with CDI. Simple Tomcat server is plain servlet container, which supports servlet and JSP technology, but not an CDI technology.
Немає коментарів:
Дописати коментар