Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add protobuf example #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
### VisualStudioCode template
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace


# Local History for Visual Studio Code
.history/
Expand Down Expand Up @@ -97,6 +93,7 @@ target/
lib_managed/
src_managed/
project/boot/
project/project
project/plugins/project/
.history
.cache
Expand Down
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ name := "my_custom_deserializers"
version := sys.env.getOrElse("CREATED_TAG", "0.1")
scalaVersion := "2.13.7"
libraryDependencies += "org.apache.kafka" % "kafka-clients" % "2.8.1"
libraryDependencies ++= Seq(
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"com.thesamet.scalapb.common-protos" %% "proto-google-common-protos-scalapb_0.11" % "2.5.0-2" % "protobuf",
"com.thesamet.scalapb.common-protos" %% "proto-google-common-protos-scalapb_0.11" % "2.5.0-2"
)

assembly / assemblyJarName := "plugins.jar"

// ## Github Packages publish configs
// More info, see: https://gist.github.com/guizmaii/2ca47b74ad8e26c772d7df6ada8ddb00
val GITHUB_OWNER = "conduktor"
val GITHUB_PROJECT = "my_custom_deserializers"

Compile / PB.targets := Seq(
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
)

ThisBuild / publishTo := Some(
s"GitHub $GITHUB_OWNER Apache Maven Packages" at s"https://maven.pkg.github.com/$GITHUB_OWNER/$GITHUB_PROJECT"
)
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
3 changes: 3 additions & 0 deletions project/scalapb.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.thesamet" % "sbt-protoc" % "1.0.3")

libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1"
26 changes: 26 additions & 0 deletions src/main/protobuf/addressbook.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto2";

package io.example.conduktor.custom.deserializers;

message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;

enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}

message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}

repeated PhoneNumber phones = 4;
}

message AddressBook {
repeated Person people = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.example.conduktor.custom.deserializers

import org.apache.kafka.common.serialization.{Deserializer, Serializer}
import io.example.conduktor.custom.deserializers.addressbook._

final class MyCustomProtobufSerializer extends Serializer[Person] {
override def serialize(topic: String, data: Person): Array[Byte] = data.toByteArray
}

final class MyCustomProtobufDeserializer extends Deserializer[Person] {
override def deserialize(topic: String, data: Array[Byte]): Person = {
Person.parseFrom(data)
}
}