How highly successful people became who we are and what will happen if we try to imitate them. Studies if universal laws of success give curios insights.
Avro Converter and Spring MVC integration for efficient serialization of Apache Avro binaries between different Message-Driven components. Converting Avro object from/to JSON and XML documents.
Having this in mind it is easy to define use-cases for Apache Avro:
Further in this article we’re going to make an overview of Avro Converter and Apache Avro while designing a Message-Driven system with Spring Boot/Spring MVC as REST API which operates JSON and XML documents received from client applications like: AngularJS, REST Client or any third-party service and Apache Kafka as Pub/Sub distributed streaming platform.
At this point you might’ve thought already: “Why do we need to have a deal with non-Avro documents?” — the answer on this is quite pragmatic:
Finally, after some analysis we can make a design overview of our toy-service with Message-Driven architecture:
Defining Avro Schema. The first step which we are going to do in our toy example is a design of an object which is going to be transferred between system components.
Fortunately, there is Maven plugin avro-maven-plugin
responsible for POJO generation based on Avro Schema files, it will automatically create EmailData
class on the project build stage. We will need it to complete our next steps.
Describing REST Endpoints with Serialization of Apache Avro Object via Spring MVC. For this step the target looks extremely simple: we need to define REST interface using Spring Boot/Spring MVC and set in use newly generated Apache Avro EmailData
object for @ReqestBody
and return type as well.
Facing an Issue. Finally, after running this basic application and triggering a PUT request with a CURL command we’re able to define a problem:
In few simple words standard MappingJackson2HttpMessageConverter
says: “Sorry. I can’t serrialize your this object just because I don't know anything about it”.
That’s where Avro Converter comes into play.
We figured out already that default for Spring Boot/Spring MVC message converter can’t handle Apache Avro objects, that’s why we will introduce Avro Converter to this project.
In order to use Avro Converter Java library on your project you will need corresponding Maven dependency:
Manual Operations. To perform manual convertions we have to get in use one of the following classes responsible for convertion of XML and JSON documents to Apache Avro objects and vice-versa: XmlToAvroConverter
, JsonToAvroConverter
, AvroToXmlConverter
, AvroToJsonConverter
:
Declare HTTP Message Converters (Spring MVC only). Integration with Spring MVC looks even easier, there are only 2 classes which we have to declare as message converters, so they could handle application/avro-json
and application/avro-xml
content types:
In the last step of our journey we will specify to already designed REST endpoints the content type which they are going to handle. Avro Converter has predefined variables for this purpose, however you can use your own:
Well, now you’re set to design of your own much more serious distributed Message-Driven systems and business scenarios with the help of Avro Converter, Apache Kafka, Apache Avro and Spring Boot.
Take it easy!
Semua orang mau menjadi sukses, makmur, dan berkelimpahan. Termasuk Anda bukan? Nah, permasalahannya adalah: Mengapa banyak orang yang tidak bisa mencapai hal tersebut? Nah, meskipun factor luar…
We had a wonderful time at the Upbit Developer Conference 2022, presenting PlayDapp! We operated the PlayDapp booth from September 22nd — 23rd, 2022, and many attendees visited our booth to learn…
Reading remains loaded with knowledge for people of every age group. If you are expecting a child, reading for your baby in the womb can be another good thing. Taking the time each day to read simple…