Sunday, January 3, 2016

Make your application more resilient with Retry4j



Nowdays, it's very important to serve a service of quality to your users. It means that your aplication's uptime must be uninterrupted or at least very near to that. Under these requirements, there are patterns to implement that. And of course, there are libraries which wrap this patterns, like probably you know Hystrix from Netflix.

But around big projects like Hystrix, always are projects more minimalistic or simple like Retry4j. This project implements stability patterns like Timeout and Circuit Breaker in a very easy way using builders. It has not any external dependency and you can integrate the Retry4j objects with your IoC without problems.

Take a look to its documentation here.

Friday, January 1, 2016

Mapping beans with Orika library

Today I want to talk about one of this useful tools that sometime can do our life more easy :).

Normally, when your are designing an enterprise application, your domain model is contained in your application's service layer. Over this layer (controllers), the communication is performed using DTOs, then you only are transfering the required information by your different clients (web user interface, another backend application, mobile applications and so on).  It is in this point where Orika can help us.

Let me show you an example. Imagine you have this domain object.


Imagine you need two different endpoints to serves information about persons. One of them must to return a basic person information, and the other one must to return the complete information about the person. As you can imagine, you need two DTOs to transfer the required information into the body's response (using json or whatever you want).

Here are our DTOs.



Well, at this point you have to transform the response of our service (service layer) that returns a domain object into the different DTOs required by the different endpoints. Orika can do that in a simple way. The key concepts are MappingFactory and MappingFacade. Orika by default maps the properties with the same name and type.

Take a look.


In fact, this example is very simple, but Orika supports more complex mappings. You can find a complete Orika's guide here.

Happy new year!