Last active
April 25, 2020 13:35
-
-
Save susliko/4113792adc4f0b796644e63bd01c5a48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Специальный тип, который утверждает, что для T есть схема | |
// и экземпляр T можно превратить в record | |
trait AvroRecord[T] { | |
val getSchema: String | |
def toRecord(value: T): String | |
} | |
// моделируем какие-то наши данные | |
case class SourcedPoint(someData: String) | |
// объект-компаньон это как "хранилище" статических значений | |
object SourcedPoint { | |
// вот это определение говорит, что наш SourcedPoint обладает свойством AvroRecord | |
// implicit означает, что это значение подтянется при вызове функций, где требуется | |
// (implicit foo: AvroRecord[SourcedPoint]) | |
implicit val avroRecord: AvroRecord[SourcedPoint] = new AvroRecord[SourcedPoint] { | |
val getSchema: String = "schema for sourced poing" | |
def toRecord(value: SourcedPoint): String = value.someData | |
} | |
} | |
object RouteProcessor { | |
// для типа T требуем подтверждение, что его можно загнать в avro | |
def setup[T](topicName: String)(implicit avro: AvroRecord[T]): List[String] = { | |
val schema = avro.getSchema | |
Nil | |
} | |
} | |
object Foo extends App { | |
RouteProcessor.setup[SourcedPoint]("topic") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment