-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Daniel Smedley <[email protected]>
- Loading branch information
1 parent
c1c8242
commit a082ec5
Showing
6 changed files
with
156 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
scheduler.reader { | ||
schedule-topics = [${?SCHEDULE_TOPICS}] | ||
kafka-brokers = "localhost:9092" | ||
kafka-brokers = ${?KAFKA_BROKERS} | ||
} | ||
|
||
kafka { | ||
consumer { | ||
bootstrap-servers = ${scheduler.reader.kafka-brokers} | ||
properties = { | ||
"group.id": "com.sky.kafka.scheduler" | ||
"group.id": ${?CONSUMER_GROUP_ID} | ||
"auto.offset.reset": "earliest" | ||
"security.protocol": PLAINTEXT | ||
"security.protocol": ${?SECURITY_PROTOCOL} | ||
"ssl.keystore.location": ${?KEYSTORE_LOCATION} | ||
"ssl.keystore.password": ${?KEYSTORE_PASSWORD} | ||
"ssl.truststore.location": ${?TRUSTSTORE_LOCATION} | ||
"ssl.truststore.password": ${?TRUSTSTORE_PASSWORD} | ||
"ssl.endpoint.identification.algorithm": "" | ||
} | ||
} | ||
|
||
producer { | ||
bootstrap-servers = ${scheduler.reader.kafka-brokers} | ||
properties = { | ||
"buffer.memory": 80000000 | ||
"batch.size": 500000 | ||
"linger.ms": 100 | ||
"security.protocol": PLAINTEXT | ||
"security.protocol": ${?SECURITY_PROTOCOL} | ||
"ssl.keystore.location": ${?KEYSTORE_LOCATION} | ||
"ssl.keystore.password": ${?KEYSTORE_PASSWORD} | ||
"ssl.truststore.location": ${?TRUSTSTORE_LOCATION} | ||
"ssl.truststore.password": ${?TRUSTSTORE_PASSWORD} | ||
"ssl.endpoint.identification.algorithm": "" | ||
} | ||
} | ||
|
||
commit { | ||
max-batch = 250 | ||
max-interval = 10 seconds | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
package uk.sky.scheduler | ||
|
||
import cats.data.Reader | ||
import cats.effect.* | ||
import fs2.Stream | ||
import org.typelevel | ||
import org.typelevel.log4cats.LoggerFactory | ||
import org.typelevel.log4cats.slf4j.Slf4jFactory | ||
import pureconfig.ConfigSource | ||
import pureconfig.module.catseffect.syntax.* | ||
import uk.sky.scheduler.config.Config | ||
|
||
object Main extends IOApp.Simple { | ||
|
||
def stream[IO[_] : Concurrent]: Stream[IO, Unit] = | ||
def stream: Reader[Config, Stream[IO, Unit]] = | ||
for { | ||
scheduler <- Stream.resource(Scheduler.live[IO]) | ||
message <- scheduler.stream | ||
} yield message | ||
scheduler <- Scheduler.live[IO] | ||
stream <- Reader[Config, Stream[IO, Scheduler[IO, Unit]]](_ => Stream.resource(scheduler)) | ||
} yield stream.flatMap(_.stream) | ||
|
||
override def run: IO[Unit] = stream[IO].compile.drain | ||
override def run: IO[Unit] = for { | ||
given LoggerFactory[IO] <- IO(Slf4jFactory.create[IO]) | ||
logger <- LoggerFactory[IO].create | ||
config <- ConfigSource.default.loadF[IO, Config]() | ||
_ <- logger.info(s"Running ${Config.metadata.appName} with version ${Config.metadata.version}") | ||
_ <- logger.info(s"Loaded config: $config") | ||
_ <- stream(config).compile.drain | ||
} yield () | ||
|
||
} |
This file contains 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
64 changes: 64 additions & 0 deletions
64
scheduler-3/src/main/scala/uk/sky/scheduler/config/Config.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package uk.sky.scheduler.config | ||
|
||
import cats.effect.{Resource, Sync} | ||
import fs2.kafka.* | ||
import pureconfig.ConfigReader | ||
import uk.sky.BuildInfo | ||
|
||
import scala.concurrent.duration.FiniteDuration | ||
|
||
final case class Config( | ||
kafka: KafkaConfig, | ||
scheduler: SchedulerConfig | ||
) derives ConfigReader | ||
|
||
object Config { | ||
private[config] final case class Metadata(appName: String, version: String) | ||
val metadata: Metadata = Metadata(appName = BuildInfo.name, version = BuildInfo.version) | ||
} | ||
|
||
final case class KafkaConfig( | ||
consumer: ConsumerProducerConfig, | ||
producer: ConsumerProducerConfig, | ||
commit: CommitConfig | ||
) derives ConfigReader | ||
|
||
object KafkaConfig { | ||
extension (config: KafkaConfig) { | ||
def consumerSettings[F[_] : Sync, K, V](using | ||
Resource[F, KeyDeserializer[F, K]], | ||
Resource[F, ValueDeserializer[F, V]] | ||
): ConsumerSettings[F, K, V] = | ||
ConsumerSettings[F, K, V] | ||
.withBootstrapServers(config.consumer.bootstrapServers) | ||
.withProperties(config.consumer.properties) | ||
.withAutoOffsetReset(AutoOffsetReset.Earliest) | ||
|
||
def producerSettings[F[_] : Sync, K, V](using | ||
Resource[F, KeySerializer[F, K]], | ||
Resource[F, ValueSerializer[F, V]] | ||
): ProducerSettings[F, K, V] = | ||
ProducerSettings[F, K, V] | ||
.withBootstrapServers(config.producer.bootstrapServers) | ||
.withProperties(config.producer.properties) | ||
} | ||
} | ||
|
||
final case class ConsumerProducerConfig( | ||
bootstrapServers: String, | ||
properties: Map[String, String] | ||
) derives ConfigReader | ||
|
||
final case class CommitConfig( | ||
maxBatch: Int, | ||
maxInterval: FiniteDuration | ||
) derives ConfigReader | ||
|
||
final case class SchedulerConfig( | ||
reader: ReaderConfig | ||
) derives ConfigReader | ||
|
||
final case class ReaderConfig( | ||
scheduleTopics: List[String], | ||
kafkaBrokers: String | ||
) derives ConfigReader |