In our daily life, we may sometime want to take the server log into the browser. We have a lot of solutions to get this working. I am going to explain some interesting solution for real-time logging using log4j, JMS and websocket.
We all are familiar with log4j, so we don’t need much more explanation. Normally, we use fileAppender to write logs into file. Apache log4j has a feature to send the log messages to a JMS borker, which is called JMSAppender.
Here, in this example, I am using ActiveMQ as message broker. It is an open source message broker written in java together with a full Java Message Service client. We can use activeMQ by embedding into tomcat or by installing and running as a different server. Normally activeMQ start listening to a default TCP port 61616.
To use ActiveMQ as a destination of our messages, we need to configure JMS appender properly. The code sample...
There are many technologies that the server will send data to the client in the very moment it knows that the new data is available such as push, comet ,etc. These all are making an illusion that the server initiated the connection called long polling. With the long polling, client opens a HTTP connection to the server and keeps it open until it receives a response. These techniques work quite well, we use them daily in application such as Gtalk.
All of these work-around has one problem such as they carry the overhead of HTTP and will not be suited for low latency applications.
WebSocket: Sockets into the web
The websocket defines an API establishing socket connection between a browser and a server. Simply, it is a persistent connection between the client and the server and both parties can send data at any time. It is an independent TCP-based protocol. Its only relationship to HTTP is that the handshake is handled using HTTP servers as an Upgrade...