Skip to content

Commit

Permalink
Kafka WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
keynmol committed Dec 1, 2023
1 parent 225d57d commit 9df0dda
Show file tree
Hide file tree
Showing 4 changed files with 5,852 additions and 0 deletions.
28 changes: 28 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ lazy val git = project
)
.settings(configurePlatform())

lazy val kafka = project
.in(file("example-kafka"))
.enablePlugins(ScalaNativePlugin, BindgenPlugin, VcpkgNativePlugin)
.settings(
scalaVersion := Versions.Scala,
vcpkgDependencies := VcpkgDependencies("librdkafka", "lz4", "openssl"),
vcpkgNativeConfig ~= {
_.addRenamedLibrary("librdkafka", "rdkafka-static")
},
bindgenBindings += {
Binding(
vcpkgConfigurator.value.includes("librdkafka") / "librdkafka" / "rdkafka.h",
"librdkafka",
linkName = Some("rdkafka"),
cImports = List("rdkafka.h")
)
}
)
.settings(configurePlatform(), checkInBindings)

lazy val postgres =
project
.in(file("example-postgres"))
Expand Down Expand Up @@ -480,6 +500,14 @@ ThisBuild / commands += Command.arb { s =>

}

val checkInBindings = Seq(
bindgenMode := BindgenMode.Manual(
scalaDir =
(Compile / sourceDirectory).value / "scala" / "generated",
cDir = (Compile / resourceDirectory).value / "scala-native"
)
)

ThisBuild / commands += Command.command("runExamples") { st =>
projectCommands(st).foldLeft(st) { case (s, n) =>
n :: s
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions example-kafka/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import librdkafka.all.*

import scalanative.unsafe.*
import scalanative.unsigned.*

@main def hello =
val conf = rd_kafka_conf_new()
val errstr = stackalloc[Byte](512)
val producer =
rd_kafka_new(rd_kafka_type_t.RD_KAFKA_PRODUCER, conf, errstr, 512.toUInt)

val topic = "purchases"

println(producer)
Loading

0 comments on commit 9df0dda

Please sign in to comment.