I’ve been playing around with concepts to alert users in real time of information they need to do their jobs. In this post I describe what I’ve achieved so far.
Now you have built an AJAX powered, uber fast web interface you need to get hold of the data. One of MarkLogic’s strengths is in alerting. This means you can register a search as a reverse query. So rather than say ‘Give me all tweets that are sent from, or mention, Surrey’ you instead say ‘Tell me when a new tweet arrives that are sent from or mention Surrey’. This means you can go away and do some other work and be alerted when new data arrives. This is great when MarkLogic is used to alert some other system, such as a Business Process Management (BPM) system, but falls down when it comes to a web interface.
Fear ye not, there is a solution! Ye olde faithful Node.js is there to help! This is a very, very lightweight event oriented server architecture. Designed to be low latency and low on its IO use, a Node.js server can be constructed that has an app server waiting for an alert to be fired from MarkLogic. This alert is then sent down the conduit between the client browser and Node.js. This is possible as Node.js has a few API available that allow the construction of a WebSockets server.
Having Node.js as a middle tier sounds like extra complexity, but actually it could make client code neater. You can have many user interfaces ‘login’ to your WebSockets server. This in turn may register itself as a listener on behalf of the user, and set up the alerts in MarkLogic automatically when a user logs in. This removes MarkLogic REST code from the client browser, making that interface more responsive and simpler. It also means you can control exactly the communication from your MarkLogic server to any clients. This separation is desirable in high secure or very remote client installations.
Hopefully this has given a flavour. I have some sample Node.js code for such a server. If you’re interested in seeing it, then leave a comment!