Skip to content

Instantly share code, notes, and snippets.

@iundarigun
Last active May 4, 2020 11:52
Show Gist options
  • Select an option

  • Save iundarigun/ed0156124a347b90170e4c10c66099f1 to your computer and use it in GitHub Desktop.

Select an option

Save iundarigun/ed0156124a347b90170e4c10c66099f1 to your computer and use it in GitHub Desktop.
MessageHandler2
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