Microservice application to get all world currencies and make a connection between client and server websocket.
Microservice with REST endpoint – “/download-currencies”. This endpoint can be hit numerous times everyday. When the endpoint being hit, we need to get the lastest information about all currencies from BNB in xml format. The data need to be saved in PostgreSql table and to send this information through websocket in JSON format so, this to happen we need this to be also websocket server. The currencies need to be saved with the bulgarian and english names. We need to create second service which reads the data and write it into another db table.
First we start the main spring method - CurrencyServiceApplication.
Go to postman and we can see the data in json format which we get it from a file from resources package.
After that we start the BnbServer. Which will create our server - BnbServerEndopint. ServerEndPoint is a class-level annotation that declares that the class it decorates is a WebSocket endpoint deployed and made available in a WebSocket server.
We start our BnbClientEndpoint and we type yes the BnbServerEndopint will create a post request to – http://localhost:8080/add-currencies
which will be handled by controller. If we want to get the info about currencies. Any other key will close the connection.
Then we go to see the database and the data in it. First for Currency.
And after that for CurrencyFromServer.
The application's public part represents endpoint to see all world currencies in json format: /download-currencies
.
When we write the new currencies in the tables, firstly we delete the old ones and after that we rewrite the data with reset id starting again from 1.