This project is a chat-like application where users can send messages to each other.
You need Java 8 installed to run this project.
You can replace mvn commands with mvnw.cmd
in Windows or ./mvnw
in Linux if you don't have Maven installed.
mvn spring-boot:run
Running from IntelliJ:
Enable Delegate IDE build/run actions to Maven
option in Settings (Preferences)
-> Build, Execution, Deployment
-> Build Tools
-> Maven
-> Runner
tab.
It is required for generating the META-INF/build.properties file.
mvn test
I used Mockito to mock the dependencies of the services.
Jacoco reports are generated here: target/site/jacoco/com.bv.actionmonitor.status/index.html
mvn integration-test
The application exposes two REST endpoints:
-
GET http://localhost:8080/status
a health check endpoint returning "OK" -
GET http://localhost:8080/version
an endpoint returning the actual version of the application in JSON formatSee them on
http://localhost:8080/swagger-ui.html
And one websocket endpoint:
-
GET http://localhost:8080/messages
an endpoint for sending messages between users. The client can upgrade to websocket protocol on this endpoint, however it is is wrapped in SockJS so clients without websocket support can use it too.You can try it here:
http://localhost:8080/app.html
. It uses basic authentication, the default users are:user1
,user2
,user3
, password ispass
for each of them.
-
Swagger endpoint for REST endpoints:
http://localhost:8080/swagger-ui.html
-
Ui for websocket:
http://localhost:8080/app.html
Auth:user1:pass
,user2:pass
,user3:pass
-
Queue monitoring (and a lot more):
http://localhost:8081/hawtio/
-
DB web console:
http://localhost:8080/h2-console
- Driver Class:
org.h2.Driver
- JDBC URL:
jdbc:h2:mem:testdb
- User Name:
sa
- Password: (leave it empty)
- Driver Class:
Major components: (See diagram)
- MessageController websocket endpoint that is the entry point for the messages
- embedded H2 database as the persistent message store
- embedded ActiveMQ as the message broker
The websocket is wrapped in by SockJS so any client that does not support websocket natively may use the system. STOMP is used as the communication protocol over the websocket which is supported by Spring and message brokers too.
- On client side there are two properties:
recipient
andcontent
. Therecipient
is the part of the destination in a STOMP header, while thecontent
is the BODY of the STOMP message. - On server side the message is extended with the
sender
which is the username of the authenticated user anddate
that is the time of receiving the message.
- the message is validated with Spring validation.
- the message is assembled and sanitized: HTML escaping is applied against XSS attacks.
- the message is stored in the database.
- the message is sent to the message broker to the message queue of the recipient.
- the message broker ensures that the message is delivered to the recipient if it is subscribed to the queue
- Exceptions are logged to the console.
- In case of a message can not be inserted to the database, the message will not be sent to the message broker. The sender is not notified about the error.
- Implement proper error handling, for example notifying the sender in case of any server-side failure
- Creating multiple type of messages
- Creating separate configuration for different environments.
- Creating proper authentication
- Creating stress tests
- Finetuning database and ActiveMQ: for example purging inactive destinations automatically