Reputation: 6572
I'm developing a monitoring application using websocket technology (Java Websocket).
I'm planing to display records in a web page when data inserted in to my database (Mysql) table.
This Mysql server is isolated from my production servers and this is only use for that monitoring service.
As an example -: when one record get inserted in to database table. I want to show that data in my wabpage as soon as it get inserted.
I have understanding of how websocket work and I'm try to approach it in this way.
I will have a infinte loop [while(true)] in my code to check current row count with a previous count and if it increased I'll extract newly inserted data from db and tel my websocket connection to update the web page.
I would be grateful if you could advice on my approach. whether I'm doing right thing or is there any alternative good approach/technologies for this purpose.
Upvotes: 0
Views: 85
Reputation: 125855
Rather than wasting CPU in the busy wait loop, you probably ought to define a trigger that notifies your process of newly inserted data.
Alternatively, you could use a messaging layer to which updates get submitted and different handlers (e.g. one to store the update in the database, another to push the update to web users) register themselves to receive and process the message.
Other than that, your design sounds reasonable to me.
Upvotes: 1