From 537c39c3d29e45c3f74995dd6f0113ecd8d64c3a Mon Sep 17 00:00:00 2001 From: "Miroslav Chomut (CZ)" Date: Wed, 16 Oct 2024 10:29:16 +0200 Subject: [PATCH 1/2] #25 better naming --- .../reader/ReaderUsingsResourceHandling.scala} | 2 +- .../writer/WriterUsingsResourceHandling.scala} | 2 +- ...ng.scala => ReaderUsingsResourceHandling.scala} | 2 +- ...ng.scala => WriterUsingsResourceHandling.scala} | 2 +- .../za/co/absa/kafkacase/examples/KafkaCase.scala | 14 ++++++++------ ...ng.scala => ReaderCustomResourceHandling.scala} | 2 +- ...ng.scala => ReaderManualResourceHandling.scala} | 2 +- ...ng.scala => WriterCustomResourceHandling.scala} | 2 +- ...ng.scala => WriterManualResourceHandling.scala} | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) rename examples/src/main/scala-2/{za.co.absa.kafkacase.examples/reader/UsingsResourceHandling.scala => za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala} (95%) rename examples/src/main/scala-2/{za.co.absa.kafkacase.examples/writer/UsingsResourceHandling.scala => za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala} (95%) rename examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/{UsingsResourceHandling.scala => ReaderUsingsResourceHandling.scala} (96%) rename examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/{UsingsResourceHandling.scala => WriterUsingsResourceHandling.scala} (96%) rename examples/src/main/scala/za/co/absa/kafkacase/examples/reader/{CustomResourceHandling.scala => ReaderCustomResourceHandling.scala} (96%) rename examples/src/main/scala/za/co/absa/kafkacase/examples/reader/{ManualResourceHandling.scala => ReaderManualResourceHandling.scala} (96%) rename examples/src/main/scala/za/co/absa/kafkacase/examples/writer/{CustomResourceHandling.scala => WriterCustomResourceHandling.scala} (96%) rename examples/src/main/scala/za/co/absa/kafkacase/examples/writer/{ManualResourceHandling.scala => WriterManualResourceHandling.scala} (96%) diff --git a/examples/src/main/scala-2/za.co.absa.kafkacase.examples/reader/UsingsResourceHandling.scala b/examples/src/main/scala-2/za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala similarity index 95% rename from examples/src/main/scala-2/za.co.absa.kafkacase.examples/reader/UsingsResourceHandling.scala rename to examples/src/main/scala-2/za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala index 9b6dc97..bfad790 100644 --- a/examples/src/main/scala-2/za.co.absa.kafkacase.examples/reader/UsingsResourceHandling.scala +++ b/examples/src/main/scala-2/za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala @@ -19,7 +19,7 @@ package za.co.absa.kafkacase.examples.reader import io.circe.Decoder import java.util.Properties -object UsingsResourceHandling { +object ReaderUsingsResourceHandling { def apply[T: Decoder](readerProps: Properties, topicName: String): Unit = { println("Scala 3 feature") } diff --git a/examples/src/main/scala-2/za.co.absa.kafkacase.examples/writer/UsingsResourceHandling.scala b/examples/src/main/scala-2/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala similarity index 95% rename from examples/src/main/scala-2/za.co.absa.kafkacase.examples/writer/UsingsResourceHandling.scala rename to examples/src/main/scala-2/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala index 08adf1b..59ac572 100644 --- a/examples/src/main/scala-2/za.co.absa.kafkacase.examples/writer/UsingsResourceHandling.scala +++ b/examples/src/main/scala-2/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala @@ -19,7 +19,7 @@ package za.co.absa.kafkacase.examples.writer import io.circe.Encoder import java.util.Properties -object UsingsResourceHandling { +object WriterUsingsResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { println("Scala 3 feature") } diff --git a/examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/UsingsResourceHandling.scala b/examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala similarity index 96% rename from examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/UsingsResourceHandling.scala rename to examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala index e3d9b2e..9614e9c 100644 --- a/examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/UsingsResourceHandling.scala +++ b/examples/src/main/scala-3/za/co/absa/kafkacase/examples/reader/ReaderUsingsResourceHandling.scala @@ -22,7 +22,7 @@ import za.co.absa.kafkacase.reader.ReaderImpl import java.util.Properties import scala.util.Using -object UsingsResourceHandling { +object ReaderUsingsResourceHandling { def apply[T: Decoder](readerProps: Properties, topicName: String): Unit = { Using(new ReaderImpl[T](readerProps, topicName, neverEnding = false)) { reader => for (item <- reader) diff --git a/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/UsingsResourceHandling.scala b/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala similarity index 96% rename from examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/UsingsResourceHandling.scala rename to examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala index d73116d..e7676fd 100644 --- a/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/UsingsResourceHandling.scala +++ b/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala @@ -22,7 +22,7 @@ import za.co.absa.kafkacase.writer.WriterImpl import java.util.Properties import scala.util.Using -object UsingsResourceHandling { +object WriterUsingsResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { Using(new WriterImpl[T](writerProps, topicName)) { writer => writer.Write("sampleMessageKey1", sampleMessageToWrite) diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/KafkaCase.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/KafkaCase.scala index 2b716bc..d8d6236 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/KafkaCase.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/KafkaCase.scala @@ -18,6 +18,8 @@ package za.co.absa.kafkacase.examples import org.apache.kafka.clients.consumer.ConsumerConfig import org.apache.kafka.clients.producer.ProducerConfig +import za.co.absa.kafkacase.examples.reader.{ReaderCustomResourceHandling, ReaderManualResourceHandling, ReaderUsingsResourceHandling} +import za.co.absa.kafkacase.examples.writer.{WriterCustomResourceHandling, WriterManualResourceHandling, WriterUsingsResourceHandling} import za.co.absa.kafkacase.models.topics.EdlaChange import java.util.{Properties, UUID} @@ -57,11 +59,11 @@ object KafkaCase { def main(args: Array[String]): Unit = { - writer.ManualResourceHandling(writerProps, topicName, sampleMessageToWrite) - writer.CustomResourceHandling(writerProps, topicName, sampleMessageToWrite) - writer.UsingsResourceHandling(writerProps, topicName, sampleMessageToWrite) - reader.ManualResourceHandling[EdlaChange](readerProps, topicName) - reader.CustomResourceHandling[EdlaChange](readerProps, topicName) - reader.UsingsResourceHandling[EdlaChange](readerProps, topicName) + WriterManualResourceHandling(writerProps, topicName, sampleMessageToWrite) + WriterCustomResourceHandling(writerProps, topicName, sampleMessageToWrite) + WriterUsingsResourceHandling(writerProps, topicName, sampleMessageToWrite) + ReaderManualResourceHandling[EdlaChange](readerProps, topicName) + ReaderCustomResourceHandling[EdlaChange](readerProps, topicName) + ReaderUsingsResourceHandling[EdlaChange](readerProps, topicName) } } diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/CustomResourceHandling.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ReaderCustomResourceHandling.scala similarity index 96% rename from examples/src/main/scala/za/co/absa/kafkacase/examples/reader/CustomResourceHandling.scala rename to examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ReaderCustomResourceHandling.scala index 64eded9..3f8c50e 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/CustomResourceHandling.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ReaderCustomResourceHandling.scala @@ -22,7 +22,7 @@ import za.co.absa.kafkacase.reader.ReaderImpl import java.util.Properties -object CustomResourceHandling { +object ReaderCustomResourceHandling { def apply[T: Decoder](readerProps: Properties, topicName: String): Unit = { withResource(new ReaderImpl[T](readerProps, topicName, neverEnding = false))(reader => { for (item <- reader) diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ManualResourceHandling.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ReaderManualResourceHandling.scala similarity index 96% rename from examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ManualResourceHandling.scala rename to examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ReaderManualResourceHandling.scala index f04ed25..fb14420 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ManualResourceHandling.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/reader/ReaderManualResourceHandling.scala @@ -21,7 +21,7 @@ import za.co.absa.kafkacase.reader.ReaderImpl import java.util.Properties -object ManualResourceHandling { +object ReaderManualResourceHandling { def apply[T: Decoder](readerProps: Properties, topicName: String): Unit = { val reader = new ReaderImpl[T](readerProps, topicName, neverEnding = false) try { diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/CustomResourceHandling.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala similarity index 96% rename from examples/src/main/scala/za/co/absa/kafkacase/examples/writer/CustomResourceHandling.scala rename to examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala index 829c234..eaef622 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/CustomResourceHandling.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala @@ -22,7 +22,7 @@ import za.co.absa.kafkacase.writer.WriterImpl import java.util.Properties -object CustomResourceHandling { +object WriterCustomResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { withResource(new WriterImpl[T](writerProps, topicName))(writer => { writer.Write("sampleMessageKey1", sampleMessageToWrite) diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/ManualResourceHandling.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala similarity index 96% rename from examples/src/main/scala/za/co/absa/kafkacase/examples/writer/ManualResourceHandling.scala rename to examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala index ae2c2b0..6e16b09 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/ManualResourceHandling.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala @@ -21,7 +21,7 @@ import za.co.absa.kafkacase.writer.WriterImpl import java.util.Properties -object ManualResourceHandling { +object WriterManualResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { val writer = new WriterImpl[T](writerProps, topicName) try { From df1208df5b8fcdf56dd23ad2059c97e96d6a8fa0 Mon Sep 17 00:00:00 2001 From: "Miroslav Chomut (CZ)" Date: Wed, 16 Oct 2024 10:31:48 +0200 Subject: [PATCH 2/2] writer method made lowercase --- .../examples/writer/WriterUsingsResourceHandling.scala | 4 ++-- .../examples/writer/WriterCustomResourceHandling.scala | 4 ++-- .../examples/writer/WriterManualResourceHandling.scala | 4 ++-- .../scala/za/co/absa/kafkacase/writer/Writer.scala | 10 +++++----- .../scala/za/co/absa/kafkacase/writer/WriterImpl.scala | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala b/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala index e7676fd..335b8b9 100644 --- a/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala +++ b/examples/src/main/scala-3/za/co/absa/kafkacase/examples/writer/WriterUsingsResourceHandling.scala @@ -25,8 +25,8 @@ import scala.util.Using object WriterUsingsResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { Using(new WriterImpl[T](writerProps, topicName)) { writer => - writer.Write("sampleMessageKey1", sampleMessageToWrite) - writer.Write("sampleMessageKey2", sampleMessageToWrite) + writer.write("sampleMessageKey1", sampleMessageToWrite) + writer.write("sampleMessageKey2", sampleMessageToWrite) } } } diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala index eaef622..4e60f67 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterCustomResourceHandling.scala @@ -25,8 +25,8 @@ import java.util.Properties object WriterCustomResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { withResource(new WriterImpl[T](writerProps, topicName))(writer => { - writer.Write("sampleMessageKey1", sampleMessageToWrite) - writer.Write("sampleMessageKey2", sampleMessageToWrite) + writer.write("sampleMessageKey1", sampleMessageToWrite) + writer.write("sampleMessageKey2", sampleMessageToWrite) }) } } diff --git a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala index 6e16b09..0a76400 100644 --- a/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala +++ b/examples/src/main/scala/za/co/absa/kafkacase/examples/writer/WriterManualResourceHandling.scala @@ -25,8 +25,8 @@ object WriterManualResourceHandling { def apply[T: Encoder](writerProps: Properties, topicName: String, sampleMessageToWrite: T): Unit = { val writer = new WriterImpl[T](writerProps, topicName) try { - writer.Write("sampleMessageKey1", sampleMessageToWrite) - writer.Write("sampleMessageKey2", sampleMessageToWrite) + writer.write("sampleMessageKey1", sampleMessageToWrite) + writer.write("sampleMessageKey2", sampleMessageToWrite) } finally { writer.close() } diff --git a/writer/src/main/scala/za/co/absa/kafkacase/writer/Writer.scala b/writer/src/main/scala/za/co/absa/kafkacase/writer/Writer.scala index b2616a2..85b07c1 100644 --- a/writer/src/main/scala/za/co/absa/kafkacase/writer/Writer.scala +++ b/writer/src/main/scala/za/co/absa/kafkacase/writer/Writer.scala @@ -17,11 +17,11 @@ package za.co.absa.kafkacase.writer trait Writer[TType] extends AutoCloseable { - def Write(key: String, value: TType): Unit - def Flush(): Unit + def write(key: String, value: TType): Unit + def flush(): Unit - def WriteSync(key: String, value: TType): Unit = { - Write(key, value) - Flush() + def writeSync(key: String, value: TType): Unit = { + write(key, value) + flush() } } diff --git a/writer/src/main/scala/za/co/absa/kafkacase/writer/WriterImpl.scala b/writer/src/main/scala/za/co/absa/kafkacase/writer/WriterImpl.scala index 8f540a8..93d655e 100644 --- a/writer/src/main/scala/za/co/absa/kafkacase/writer/WriterImpl.scala +++ b/writer/src/main/scala/za/co/absa/kafkacase/writer/WriterImpl.scala @@ -27,12 +27,12 @@ import java.util.Properties class WriterImpl[TType: Encoder](props: Properties, topic: String) extends Writer[TType] { private val producer = new KafkaProducer[String, String](props) - def Write(key: String, value: TType): Unit = { + def write(key: String, value: TType): Unit = { log.info(f"Writing: $key => $value") producer.send(new ProducerRecord[String, String](topic, key, value.asJson.noSpaces)) } - def Flush(): Unit = producer.flush() + def flush(): Unit = producer.flush() override def close(): Unit = producer.close() }