Skip to content

Commit

Permalink
Add produce/consume in scala code (confluentinc#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
DivLoic committed Jun 28, 2020
1 parent d9001cf commit 82bbe4b
Show file tree
Hide file tree
Showing 25 changed files with 1,532 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
62 changes: 62 additions & 0 deletions _includes/tutorials/produce-consume-lang/scala/code/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import sbt.Attributed
import sbt.fullRunTask
import complete.DefaultParsers
import Dependencies._
import de.gccc.jib.JibPlugin.autoImport.{jibDockerBuild, jibRegistry}
import sbt.Keys.commands

ThisBuild / scalaVersion := "2.13.2"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "io.confluent.developer"
ThisBuild / organizationName := "confluent"

ThisBuild / javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")

ThisBuild / scalacOptions ++= Seq("-language:postfixOps")
ThisBuild / jibRegistry := ""

def dockerPackage(command: String, settings: Seq[Def.Setting[_]]): Command = Command.command(command) { state =>
val settingsState = (Project extract state).appendWithoutSession(settings, state)
val (commandState, _) = Project.extract(settingsState).runTask(jibDockerBuild, settingsState)
commandState
}

lazy val root = (project in file("."))
.settings(
name := "produce-consume-scala",
resolvers += "Confluent Repo" at "http://packages.confluent.io/maven",
libraryDependencies ++= katancsv ++: (caskHttp ::
avro4S ::
logback ::
pureConfig ::
kafkaClients ::
confluentSerde ::
scalaTest % Test ::
kafkaTestcontainers % Test :: Nil),

commands += dockerPackage("packageConsumer", Seq(
jibName := "scala-consumer",
mainClass in Compile := Some("io.confluent.developer.Consumer")
)),

commands += dockerPackage("packageProducer", Seq(
jibName := "scala-producer",
mainClass in Compile := Some("io.confluent.developer.Producer")
))
)

lazy val produce: InputKey[Unit] = inputKey[Unit]("Message Production")
produce := (runner in Compile).value.run("io.confluent.developer.Producer",
Attributed.data((fullClasspath in Compile).value),
DefaultParsers.spaceDelimited("arguments").parsed,
streams.value.log
)

lazy val consume: TaskKey[Unit] = taskKey[Unit]("Message Consumption")
fullRunTask(consume, Compile, "io.confluent.developer.Consumer")

lazy val topicCreation: TaskKey[Unit] = taskKey[Unit]("Topic creation task")
fullRunTask(topicCreation, Compile, "io.confluent.developer.helper.TopicCreation")

lazy val schemaPublication: TaskKey[Unit] = taskKey[Unit]("Schema publication task")
fullRunTask(schemaPublication, Compile, "io.confluent.developer.helper.SchemaPublication")
8 changes: 8 additions & 0 deletions _includes/tutorials/produce-consume-lang/scala/code/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'Franz Kafka','Der Prozess',Novel,239,1925-09-01
'Franz Kafka','Die Verwandlung',Novel,144,1915-01-01
'Franz Kafka','Der Bau',Novel,37,1923-01-01
'Paul Chiusano','Functional Programming in Scala',Tech,320,2014-09-01
'Stendhal','Le Rouge et le Noir',Novel,640,1830-09-01
'Émile Zola','Au Bonheur des Dames',Novel,542,1883-11-01
'Loic D.','Not the worst ramen recipe',Other,3,2020-06-01
'Neha Narkhede','Kafka: The Definitive Guide',Tech,322,2017-07-07
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
version: '3.7'

services:
zookeeper:
image: confluentinc/cp-zookeeper:5.5.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
networks:
- tutorial
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000

broker:
image: confluentinc/cp-enterprise-kafka:5.5.0
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "29092:29092"
networks:
- tutorial
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:9092
CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
CONFLUENT_METRICS_ENABLE: 'true'
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'

schema-registry:
image: confluentinc/cp-schema-registry:5.5.0
hostname: schema-registry
container_name: schema-registry
depends_on:
- zookeeper
- broker
ports:
- "8081:8081"
networks:
- tutorial
environment:
SCHEMA_REGISTRY_HOST_NAME: schema-registry
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: 'zookeeper:2181'
SCHEMA_REGISTRY_LOG4J_ROOT_LOGLEVEL: WARN

networks:
tutorial:
name: tutorial
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sbt._

object Dependencies {

// tutorial essentials
lazy val kafkaClients: ModuleID = "org.apache.kafka" % "kafka-clients" % "2.5.0"
lazy val confluentSerde: ModuleID = "io.confluent" % "kafka-streams-avro-serde" % "5.5.0"
lazy val avro4S: ModuleID = "com.sksamuel.avro4s" %% "avro4s-core" % "3.1.0"
lazy val scalaTest: ModuleID = "org.scalatest" %% "scalatest" % "3.1.1"
lazy val kafkaTestcontainers = "org.testcontainers" % "kafka" % "1.14.3"


// presentation boiler plate
lazy val logback: ModuleID = "ch.qos.logback" % "logback-classic" % "1.2.3"
lazy val pureConfig: ModuleID = "com.github.pureconfig" %% "pureconfig" % "0.12.3"
lazy val caskHttp: ModuleID = "com.lihaoyi" %% "cask" % "0.6.7"
lazy val katancsv: Seq[ModuleID] =
"com.nrinaudo" %% "kantan.csv-generic" % "0.6.1" ::
"com.nrinaudo" %% "kantan.csv-java8" % "0.6.1" ::
"com.nrinaudo" %% "kantan.csv-enumeratum" % "0.6.1" :: Nil

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.3.10
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("de.gccc.sbt" % "sbt-jib" % "0.8.0")
Loading

0 comments on commit 82bbe4b

Please sign in to comment.