Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/scala/de/otto/anthology/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ object App extends OxApp, LazyLogging:
store,
clusterSettings,
kafkaConsumers,
config.parallelism
config.parallelism,
config.domain.logThroughput
)
par(startHttpServer(), startAppWorkflow()).discard
ExitCode.Success
Expand Down
10 changes: 3 additions & 7 deletions src/main/scala/de/otto/anthology/AppWorkflow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ object AppWorkflow:
stateStore: StateStore,
clusterSettings: Map[ClusterName, KafkaClusterSettings],
kafkaConsumers: ConsumerMap,
parallelism: Parallelism
parallelism: Parallelism,
logDomainThroughput: Option[Boolean]
)(using Ox): Unit =
DomainSources(channelConfigs, kafkaConsumers)
.buffer()
DomainSources(channelConfigs, kafkaConsumers, logDomainThroughput)
.filterDomainMessages(channelConfigs, parallelism)
.buffer()
.transformDomainMessageIds(channelConfigs)
.buffer()
.transformDomainMessages(channelConfigs, parallelism)
.buffer()
.persistDomainMessages(stateStore)
Expand All @@ -65,13 +63,11 @@ object AppWorkflow:
.inlineDomainMessages(relationConfigs, stateStore, parallelism)
.buffer()
.filterCodomainMessages(codomainConfig.filtering, parallelism)
.buffer()
.transformCodomainMessages(codomainConfig.transformation, parallelism)
.buffer()
.persistCodomainMessages(stateStore, parallelism)
.buffer()
.propagateHeaders(codomainConfig.headerPropagationConfigs)
.buffer()
.emitCodomainMessages(
KafkaSinkSettings(
codomainConfig.kafka,
Expand Down
36 changes: 20 additions & 16 deletions src/main/scala/de/otto/anthology/CodomainDeduplicationStage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ object CodomainDeduplicationStage:
configOpt: Option[CodomainDeduplicationConfig]
): Flow[(Seq[(QualifiedMessageId, Seq[MessageId])], Seq[Passthrough])] =
val config = configOpt.getOrElse(defaultConfig)
in
.groupedWithin(config.batchSize, config.batchingDuration)
.map: batches =>
val passthroughs: ListBuffer[Passthrough] = ListBuffer.empty
val deduplicationMap: MutableMap[QualifiedMessageId, Set[MessageId]] = MutableMap.empty
batches.foreach: batch =>
batch._1 match
case None =>
()
case Some(domainMessageId, codomainMessageIds) =>
deduplicationMap.updateWith(domainMessageId):
case None => Some(Set.empty ++ codomainMessageIds)
case Some(curCodomainMessageIds) =>
Some(curCodomainMessageIds ++ codomainMessageIds)
passthroughs += batch._2
(deduplicationMap.map((k, v) => (k, v.toSeq)).toSeq, passthroughs.sorted.toSeq)
if config.batchSize == 1 then
in.map: (payload, passthrough) =>
(payload.toSeq.map(e => (e._1, e._2.toSeq)), Seq(passthrough))
else
in
.groupedWithin(config.batchSize, config.batchingDuration)
.map: batches =>
val passthroughs: ListBuffer[Passthrough] = ListBuffer.empty
val deduplicationMap: MutableMap[QualifiedMessageId, Set[MessageId]] = MutableMap.empty
batches.foreach: batch =>
batch._1 match
case None =>
()
case Some(domainMessageId, codomainMessageIds) =>
deduplicationMap.updateWith(domainMessageId):
case None => Some(Set.empty ++ codomainMessageIds)
case Some(curCodomainMessageIds) =>
Some(curCodomainMessageIds ++ codomainMessageIds)
passthroughs += batch._2
(deduplicationMap.map((k, v) => (k, v.toSeq)).toSeq, passthroughs.sorted.toSeq)

case class CodomainDeduplicationConfig(batchSize: Int, batchingDuration: FiniteDuration) derives ConfigReader
8 changes: 5 additions & 3 deletions src/main/scala/de/otto/anthology/DomainSources.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ object DomainSources:

def apply(
configs: ChannelConfigs,
consumers: ConsumerMap
consumers: ConsumerMap,
logThroughput: Option[Boolean]
)(using Ox): Flow[(Option[(QualifiedMessageId, Option[Message])], Passthrough)] =
configs.channels
.map: config =>
// for now we go with consumer name == domain name
val consumerName = ConsumerName(config.name.toString)
DomainSource(
val src = DomainSource(
config,
KafkaSourceSettings(config.kafka, consumerName, consumers(consumerName))
).count(s"domain source ${config.name.toString}")
)
if logThroughput.getOrElse(false) then src.count(s"domain source ${config.name.toString}") else src
.mergeFair()
4 changes: 2 additions & 2 deletions src/main/scala/de/otto/anthology/KafkaSink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ object KafkaSink extends LazyLogging:
producerRecords.foreach(publishChannel.send)
offsets.foreach(committerChannel.send)
.mapStateful(0): (cnt, _) =>
if cnt % 100 == 0 then
logger.info("Published and committed 100 batches of codomain messages to Kafka")
if cnt % 1000 == 0 then
logger.info("Published and committed 1000 batches of codomain messages to Kafka")
(cnt + 1, ())
.runDrain()

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/de/otto/anthology/config/DomainConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package de.otto.anthology.config
import de.otto.anthology.ChannelName
import pureconfig.ConfigReader

case class DomainConfig(channels: Seq[ChannelConfig], relations: Seq[RelationConfig]) derives ConfigReader:
case class DomainConfig(channels: Seq[ChannelConfig], relations: Seq[RelationConfig], logThroughput: Option[Boolean])
derives ConfigReader:
val channelsByName: Map[ChannelName, ChannelConfig] = channels.map(c => (c.name, c)).toMap