-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement 'produce' aliases in the Producer trait, making producer co…
…mposition simpler
- Loading branch information
1 parent
6cddf50
commit 95b921c
Showing
2 changed files
with
42 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
package zio.kafka | ||
|
||
import org.apache.kafka.clients.producer.ProducerRecord | ||
import zio.RIO | ||
import zio.kafka.serde.Serializer | ||
|
||
package object producer { | ||
type ByteRecord = ProducerRecord[Array[Byte], Array[Byte]] | ||
|
||
def serialize[R, K, V]( | ||
r: ProducerRecord[K, V], | ||
keySerializer: Serializer[R, K], | ||
valueSerializer: Serializer[R, V] | ||
): RIO[R, ByteRecord] = | ||
for { | ||
key <- keySerializer.serialize(r.topic, r.headers, r.key()) | ||
value <- valueSerializer.serialize(r.topic, r.headers, r.value()) | ||
} yield new ProducerRecord(r.topic, r.partition(), r.timestamp(), key, value, r.headers) | ||
} |