Schema and example of how to use Apache Thrift for data serialization between different components, without using RPC/services.
To compile:
mvn compile
To run:
mvn exec:java
Build it :
docker build -f Dockerfile -t thrift-test .
Run it:
docker run thrift-test
Here is the code structure in the repo:
.
βββ Dockerfile
βββ README.md
βββ pom.xml
βββ src
βββ main
βββ java
βΒ Β βββ org
βΒ Β βββ example
βΒ Β βββ EventLogger.java
βββ resources
βββ thrift
βββ event.thrift
Here, mainly two files are important:
event.thriftdefines an example event schema.EventLogger.javais an example client which will use the schema and create a JSON out of it and print it. Here is where you can do anything with the generated object (post this event to other service etc.), but for simplicity I am just printing the json on console.
Infrastructure files:
Dockerfileis usesmvnimage and installsthriftinto it.Dockerfileis very simple right now. It currently is not optimized and downloads maven dependencies each time, for example.pom.xmlis formvnand defines code dependencies, how to compile the project etc.
This is the final generated and compiled code structure.
.
βββ Dockerfile
βββ README.md
βββ pom.xml
βββ src
βΒ Β βββ main
βΒ Β βββ java
βΒ Β βΒ Β βββ org
βΒ Β βΒ Β βββ example
βΒ Β βΒ Β βββ EventLogger.java
βΒ Β βββ resources
βΒ Β βββ thrift
βΒ Β βββ event.thrift
βββ target
βββ classes
βΒ Β βββ event.thrift
βΒ Β βββ org
βΒ Β βΒ Β βββ example
βΒ Β βΒ Β βββ Event$1.class
βΒ Β βΒ Β βββ Event$EventStandardScheme.class
βΒ Β βΒ Β βββ Event$EventStandardSchemeFactory.class
βΒ Β βΒ Β βββ Event$EventTupleScheme.class
βΒ Β βΒ Β βββ Event$EventTupleSchemeFactory.class
βΒ Β βΒ Β βββ Event$_Fields.class
βΒ Β βΒ Β βββ Event.class
βΒ Β βΒ Β βββ EventLogger.class
βΒ Β βΒ Β βββ EventName.class
βΒ Β βΒ Β βββ State.class
βΒ Β βββ thrift
βΒ Β βββ event.thrift
βββ generated-sources
βΒ Β βββ thrift
βΒ Β βββ org
βΒ Β βββ example
βΒ Β βββ Event.java
βΒ Β βββ EventName.java
βΒ Β βββ State.java
βββ maven-status
βββ maven-compiler-plugin
βββ compile
βββ default-compile
βββ createdFiles.lst
βββ inputFiles.lst