Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kfyodor/kfk-avro-bridge
Converting Clojure data structures to Avro-compatible Java classes back and forth
https://github.com/kfyodor/kfk-avro-bridge
Last synced: about 1 month ago
JSON representation
Converting Clojure data structures to Avro-compatible Java classes back and forth
- Host: GitHub
- URL: https://github.com/kfyodor/kfk-avro-bridge
- Owner: kfyodor
- License: epl-1.0
- Created: 2016-08-08T14:37:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-11T18:32:01.000Z (almost 7 years ago)
- Last Synced: 2024-11-08T03:03:58.733Z (about 1 month ago)
- Language: Clojure
- Size: 14.6 KB
- Stars: 7
- Watchers: 0
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kafka-in-clojure - konukhov/kfk-avro-bridge
README
# Clojure Avro Brigde for using with Kafka and Schema Registry
[![CircleCI](https://circleci.com/gh/konukhov/kfk-avro-bridge.svg?style=shield)](https://circleci.com/gh/konukhov/kfk-avro-bridge)This library is designed specifically for converting Clojure data structures to Avro-compatible Java classes (not Avro binary format!) back and forth in order to be able to use [Schema Registry's serializers](https://github.com/confluentinc/schema-registry/blob/master/avro-serializer/src/main/java/io/confluent/kafka/serializers/KafkaAvroSerializer.java) with Kafka and Clojure.
Note, that this library is not an Avro-wrapper for Clojure: for this purpose you might want to use [damballa/abracad](https://github.com/damballa/abracad) or [asmyczek/simple-avro](https://github.com/asmyczek/simple-avro)
## Installation
Add this to your favorite build file (`project.clj` or `build.boot`)
`[io.thdr/kfk.avro-bridge "0.1.0-SNAPSHOT"]`
## Usage
#### Notes: ####
+ All keys in Clojure maps are keywordized and kebab-cased.
+ Enums are keywordized and kebab-cased
+ When converting to Java objects, all keys and enums are snake_cased.#### Example: ####
```clojure
(ns test-avro
(:require [thdr.kfk.avro-bridge.core :as avro]
[cheshire.core :as json]))(def schema (json/generate-string {:type "record",
:name "user",
:fields [{:name "id" :type "int"}
:name "full_name" :type "string"]}))(def obj (avro/->java (parse-schema schema)
{:id 1 :full-name "John Doe"}))
;; => , which can be passed to KafkaAvroSerializer, for example
(avro/->clj obj)
;; => {:id 1 :full-name "John Doe"}
```## Contributing
Feel free to open an issue or PR
## License
Copyright © 2016 Theodore Konukhov
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.