-
Notifications
You must be signed in to change notification settings - Fork 2
LeveragingAvro
Avro is one of the many new serialization formats that have been created in the last 20 years. for a good introductions and also a comparison between with probably the 2 most popular alternatives see
In this demo project we use avro for:
- wire format.
- log format.
- Multiple encodings support:
- binary for efficiency.
- json for ineroperability and debugging.
- csv for interoperability and debugging.
- Extensible. You can add you own metadata to the schema. (@beta, @displayName, ...)
- Avro schemas have a Json representation.
- Multiple language support.
- Open source.
Start up the demo app as described at.
Let's try to get some data from:
As you can observe the writer schema info is provided by the content-schema HTTP header:
Content-Length: 505
content-schema: {"type":"array","items":{"$ref":"org.spf4j.demo:jaxrs-spf4j-demo-schema:0.3:2"}}
Content-Type: application/avro-x+json;charset=UTF-8
removing ?_Accept=application/json will yield the more efficient binary response:
Content-Length: 220
content-schema: {"type":"array","items":{"$ref":"org.spf4j.demo:jaxrs-spf4j-demo-schema:0.3:2"}}
Content-Type: application/avro
If we would desire the data in CSV format, since this endpoint is compliant we can use: ?_Accept=text/csv
Content-Length: 376
content-schema: {"type":"array","items":{"$ref":"org.spf4j.demo:jaxrs-spf4j-demo-schema:0.3:2"}}
Content-Type: text/csv;fmt=avro;charset=UTF-8
All the above is magically served by a endpoint definition like:
@GET
@Produces(value = {"application/avro", "application/avro-x+json", "application/octet-stream", "application/json", "text/csv"})
List<DemoRecordInfo> getRecords();
This functionality is implemented by the spf4j avro feature and leverages Avro references
- structure. No need to write custom parsers. See for the record structure.
- efficiency. smaller in size due to binary format, and built in compression.
An example of how to use avro for logs (leverages spf4j-logback and spf4j-jaxrs-actuator) is at.
Show latest logs in text format:
Show latest logs in JSON format:
Browse cluster log files:
Show all Log files from a particular node:
Download a log file: