Last active
May 4, 2020 11:52
-
-
Save iundarigun/ed0156124a347b90170e4c10c66099f1 to your computer and use it in GitHub Desktop.
MessageHandler2
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
| class MirroringMessageHandler( | |
| private val arg: String = "" | |
| ) : MirrorMaker.MirrorMakerMessageHandler { | |
| override fun handle(record: BaseConsumerRecord?): | |
| MutableList<ProducerRecord<ByteArray, ByteArray>> { | |
| return if (record != null && mustMirroring(record)) { | |
| mutableListOf( | |
| ProducerRecord<ByteArray, ByteArray>( | |
| record.topic(), | |
| null, | |
| record.timestamp(), | |
| record.key(), | |
| record.value(), | |
| record.headers() | |
| ) | |
| ) | |
| } else { | |
| mutableListOf() | |
| } | |
| } | |
| private fun mustMirroring(record: BaseConsumerRecord): Boolean { | |
| val header = record.headers().find { it.key() == "dc-origin" } | |
| if (header == null) { | |
| record.headers().add("dc-origin", arg.toByteArray(Charsets.UTF_8)) | |
| return true | |
| } | |
| return false | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment