7

Visitor Logging in a Microservices Application

 3 years ago
source link: https://nixmash.com/java/visitor-logging-in-a-microservices-application/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Visitor Logging in a Microservices Application

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.

micro0322b.png

The Process

With our application design, the process of logging visitor activity goes like this:

  1. Obtain client info in the browser and pass it to a Controller in the Web Module as JSON.
  2. Extract the ClientInfo object to apply any business rules, then convert it to a JSON Entity and pass it to a Resource Endpoint in the Post Microservice with REST
  3. Extract the ClientInfo object in the Post Microservice and pass it to a RabbitMQ Queue as a Byte Array
  4. Pick up the ClientInfo object from the RabbitMQ Queue in the Util Microservice and save it to MySQL.

The process of logging visitor activity in a Monolithic Application, on the other hand, would be this:

  1. Obtain client info in the browser and pass it to a Controller in the Web Module as JSON.
  2. Extract the ClientInfo object to apply any business rules, then save it to MySQL.

Obtaining Client Info in the Browser

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.

log035a.png

The Web Module

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.

log035c.png

Post Service Module

In the Post Microservice the ClientInfo object is retrieved…

log035d.png

and placed on the RabbitMQ Queue as a Byte Array.

log035e.png

The Util Microservice

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.

log035f.png

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…


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK