schemaregistryconverter
This library is provides a way of using the Confluent Schema Registry in a way that is compliant with the usual jvm useage.
Consuming/decoding and producing/encoding is supported. It's also possible to provide the schema to use when decoding. When no schema is provided the latest
schema with the same subject
will be used. As far as I know it's feature complete compared to the confluent java version.
As I'm still pretty new to rust pr's/remarks for improvements are greatly appreciated.
schemaregistryconverter.rs is available on crates.io. It is recommended to look there for the newest and more elaborate documentation.
toml
[dependencies]
schema_registry_converter = "0.3.0"
...and see the docs for how to use it.
```rust extern crate rdkafka; extern crate avrors; extern crate schemaregistry_converter;
use rdkafka::message::{Message, BorrowedMessage}; use avrors::types::Value; use schemaregistryconverter::Decoder; use schemaregistryconverter::Encoder; use schemaregistryconverter::schemaregistry::SubjectNameStrategy;
fn get_value<'a>( msg: &'a BorrowedMessage, decoder: &'a mut Decoder, ) -> Value{ match decoder.decode(msg.payload()){ Ok(v) => v, Err(e) => panic!("Error getting value: {}", e), } }
fn getfuturerecord<'a>( topic: &'a str, key: Option<&'a str>, values: Vec<(&'static str, Value)>, encoder: &'a mut Encoder, ) -> FutureRecord<'a>{ let subjectnamestrategy = SubjectNameStrategy::TopicNameStrategy(topic, false); let payload = match encoder.encode(values, &subjectnamestrategy) { Ok(v) => v, Err(e) => panic!("Error getting payload: {}", e), }; FutureRecord { topic, partition: None, payload: Some(&payload), key, timestamp: None, headers: None, } }
fn main() { let mut decoder = Decoder::new(SERVERADDRESS); let mut encoder = Encoder::new(SERVERADDRESS); //somewhere else the above functions can be called } ```
The avro part of the conversion is handled by avro-rs as such I don't include tests for every possible schema. While I used rdkafka in combination to successfully consume from and produce to kafka, and it's used in the example this crate has no direct dependency to it. All this crate does is convert [u8] <-> avro_rs::types::Value.
Do to mockito, used for mocking the schema registry responses, being run in a seperate thead, tests have to be run using --test-threads=1
for example like
cargo +stable test --color=always -- --nocapture --test-threads=1
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Schema Registry Converter by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.