All Projects → daniel-shuy → kafka-protobuf-serde

daniel-shuy / kafka-protobuf-serde

Licence: MIT license
Serializer/Deserializer for Kafka to serialize/deserialize Protocol Buffers messages

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to kafka-protobuf-serde

nimpb
Protocol Buffers for Nim
Stars: ✭ 29 (-44.23%)
Mutual labels:  serialization, protobuf, protocol-buffers
Marshmallow
A lightweight library for converting complex objects to and from simple Python datatypes.
Stars: ✭ 5,857 (+11163.46%)
Mutual labels:  serialization, serde, deserialization
ocaml-pb-plugin
A protoc plugin for generating OCaml code from protobuf (.proto) files.
Stars: ✭ 18 (-65.38%)
Mutual labels:  serialization, protobuf, protocol-buffers
protoc-plugin
A protoc compiler plugin for Clojure applications
Stars: ✭ 28 (-46.15%)
Mutual labels:  serialization, protobuf, protocol-buffers
Protobuf Java Format
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
Stars: ✭ 134 (+157.69%)
Mutual labels:  serialization, protobuf, protocol-buffers
javascript-serialization-benchmark
Comparison and benchmark of JavaScript serialization libraries (Protocol Buffer, Avro, BSON, etc.)
Stars: ✭ 54 (+3.85%)
Mutual labels:  serialization, protobuf, protocol-buffers
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (+78.85%)
Mutual labels:  serialization, protobuf, protocol-buffers
protobuf-d
Protocol Buffers Compiler Plugin and Support Library for D
Stars: ✭ 32 (-38.46%)
Mutual labels:  serialization, protobuf, protocol-buffers
Typical
Typical: Fast, simple, & correct data-validation using Python 3 typing.
Stars: ✭ 111 (+113.46%)
Mutual labels:  serialization, serde, deserialization
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+100486.54%)
Mutual labels:  serialization, protobuf, protocol-buffers
serde
🚝 (unmaintained) A framework for defining, serializing, deserializing, and validating data structures
Stars: ✭ 49 (-5.77%)
Mutual labels:  serialization, serde, deserialization
avro-serde-php
Avro Serialisation/Deserialisation (SerDe) library for PHP 7.3+ & 8.0 with a Symfony Serializer integration
Stars: ✭ 43 (-17.31%)
Mutual labels:  serialization, serde, deserialization
Protobuf
A pure Elixir implementation of Google Protobuf
Stars: ✭ 442 (+750%)
Mutual labels:  serialization, protobuf, protocol-buffers
Protobuf Nim
Protobuf implementation in pure Nim that leverages the power of the macro system to not depend on any external tools
Stars: ✭ 90 (+73.08%)
Mutual labels:  serialization, protobuf, protocol-buffers
Noproto
Flexible, Fast & Compact Serialization with RPC
Stars: ✭ 138 (+165.38%)
Mutual labels:  serialization, protocol-buffers, deserialization
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-51.92%)
Mutual labels:  serialization, serde, deserialization
kafka-serde-scala
Implicitly converts typeclass encoders to kafka Serializer, Deserializer, Serde.
Stars: ✭ 52 (+0%)
Mutual labels:  serialization, serde
protobuf-ipc-example
Protocol buffer IPC example
Stars: ✭ 19 (-63.46%)
Mutual labels:  protobuf, protocol-buffers
cattrs
Complex custom class converters for attrs.
Stars: ✭ 565 (+986.54%)
Mutual labels:  serialization, deserialization
sexp-grammar
Invertible parsing for S-expressions
Stars: ✭ 28 (-46.15%)
Mutual labels:  serialization, deserialization

kafka-protobuf-serde

Branch Travis CI CodeFactor Codacy Better Code Hub Coverall
Master Build Status CodeFactor Codacy Badge BCH compliance Coverage Status
Develop Build Status CodeFactor Codacy Badge BCH compliance Coverage Status

Serializer/Deserializer for Kafka to serialize/deserialize Protocol Buffers messages

Requirements

Dependency Version
Kafka 2.X.X
Protobuf 3.X.X
Java 8+

Usage

Add the following to your Maven dependency list:

<dependency>
    <groupId>com.github.daniel-shuy</groupId>
    <artifactId>kafka-protobuf-serde</artifactId>
    <version>${kafka-protobuf-serde.version}</version>
</dependency>

Override the protobuf-java dependency with the version of Protobuf you wish to use:

<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>${protobuf.version}</version>
</dependency>

Override the kafka-clients dependency version with the version of Kafka you wish to use:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>${kafka.version}</version>
</dependency>

Kafka Producer

Properties props = new Properties();
// props.put(..., ...);

Producer<String, MyValue> producer = new KafkaProducer<>(props,
    new StringSerializer(),
    new KafkaProtobufSerializer<>());

producer.send(new ProducerRecord<>("topic", new MyValue()));

Kafka Consumer

Properties props = new Properties();
// props.put(..., ...);

Consumer<String, MyValue> consumer = new KafkaConsumer<>(props,
    new StringDeserializer(),
    new KafkaProtobufDeserializer<>(MyValue.parser()));

consumer.subscribe(Collections.singleton("topic"));
ConsumerRecords<String, MyValue> records = consumer.poll(Duration.ofMillis(100));

records.forEach(record -> {
    String key = record.key();
    MyValue value = record.value();

    // ...
});

Kafka Streams

Serde<String> stringSerde = Serdes.String();
Serde<MyValue> myValueSerde = new KafkaProtobufSerde<>(MyValue.parser());

Properties config = new Properties();
// config.put(..., ...);

StreamsBuilder builder = new StreamsBuilder();
KStream<String, MyValue> myValues = builder.stream("input_topic", Consumed.with(stringSerde, myValueSerde));
KStream<String, MyValue> filteredMyValues = myValues.filter((key, value) -> {
    // ...
});
filteredMyValues.to("output_topic", Produced.with(stringSerde, myValueSerde));

Topology topology = builder.build();
KafkaStreams streams = new KafkaStreams(topology, config);
streams.setUncaughtExceptionHandler((thread, throwable) -> {
    // ...
});
Runtime.getRuntime().addShutdownHook(new Thread(streams::close));
streams.start();

Spring for Apache Kafka (spring-kafka)

Kafka Producer

@Configuration
public class KafkaConfig {
    @Bean
    public ProducerFactory<String, MyValue> producerFactory() {
        Map<String, Object> props = new HashMap<>();
        // props.put(..., ...);

        return new DefaultKafkaProducerFactory<>(producerProps,
                new StringSerializer(),
                new KafkaProtobufSerializer<>());
    }

    @Bean
    public KafkaTemplate<String, MyValue> kafkaTemplate() {
        return new KafkaTemplate(producerFactory());
    }
}

Kafka Consumer

@Configuration
@EnableKafka
public class KafkaConfig {
    @Bean
    KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MyValue>>
            kafkaListenerContainerFactory() {
        ConcurrentKafkaListenerContainerFactory<Integer, String> factory =
            new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(consumerFactory());
        return factory;
    }

    @Bean
    public ConsumerFactory<String, MyValue> consumerFactory() {
        Map<String, Object> props = new HashMap<>();
        // props.put(..., ...);

        return new DefaultKafkaConsumerFactory<>(props,
            new StringDeserializer(),
            new KafkaProtobufDeserializer<>(MyValue.parser()));
    }
}

public class Listener {
    @KafkaListener(id = "foo", topics = "annotated1")
    public void listen1(String foo) {
        // ...
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].