I described the all new NixMash.com Microservices application in a recent post. In it I mentioned that many processes are more complex with Microservices because we're passing data among the various application components. In this post we will observe why even simple processes like logging visitor activity are more complicated in a Microservices Application.
Before getting into the code, here's a review of the layout of NixMash Microservices. The Web Module communicates with the Post Microservice through REST, which in turn communicates with the Util and Solr Microservices through RabbitMQ Message Queues.
With our application design, the process of logging visitor activity goes like this:
The process of logging visitor activity in a Monolithic Application, on the other hand, would be this:
This step would be the same in any application design. What's interesting is the use of Mustache to obtain the Post ID and how we're determining if someone is using an Ad Blocker by seeing if any iframe elements are present on the page.
The ClientInfo JSON is sent to our Web Module Controller method, then packaged for transport to our REST Post Microservice Endpoint. Here's the REST packaging of our ClientInfo object for the microservice.
In the Post Microservice the ClientInfo object is retrieved...
and placed on the RabbitMQ Queue as a Byte Array.
The Util Microservice monitors the RabbitMQ Queues as the Server, with the Post Microservice the Client. We're using two RabbitMQ Queues for our Utility processes, a one-way Queue and a two-way communications RPC Queue. Here we're using the one-way Queue, not requiring any response from the Util Microservice for our logging task.
Our task key is LOG_CLIENTINFO where you see we extract the ClientInfo object and can finally, finally, log the visit in MySQL.
We covered a lot of code here, and didn't even display all of the code involved in the process. The important point here is that if we were coding a Monolithic Application, the utilService.logClientInfo() call would have appeared in our Web Module /log Controller method and we would've been done.
Microservice design trade-offs...