-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow deriving and remapping keys (#616)
- Loading branch information
Showing
7 changed files
with
385 additions
and
15 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
22 changes: 22 additions & 0 deletions
22
core/src/main/scala/com/evolutiongaming/kafka/flow/RemapKey.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,22 @@ | ||
package com.evolutiongaming.kafka.flow | ||
|
||
import cats.Applicative | ||
import cats.syntax.applicative._ | ||
import com.evolutiongaming.skafka.consumer.ConsumerRecord | ||
import scodec.bits.ByteVector | ||
|
||
trait RemapKey[F[_]] { | ||
|
||
/** Derive a new key for the consumer record based on the current key (if there is one) and the record itself. | ||
* Deriving is done before the record is processed by the flow. Thus, the next steps in the flow (such as | ||
* [[FilterRecord]] and [[FoldOption]]) will see the remapped key in the consumer record. | ||
*/ | ||
def remap(key: String, record: ConsumerRecord[String, ByteVector]): F[String] | ||
} | ||
|
||
object RemapKey { | ||
def of[F[_]](f: (String, ConsumerRecord[String, ByteVector]) => F[String]): RemapKey[F] = (key, record) => | ||
f(key, record) | ||
|
||
def empty[F[_]: Applicative]: RemapKey[F] = (key, _) => key.pure[F] | ||
} |
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 |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
|
||
</configuration> | ||
</configuration> |
Oops, something went wrong.