There is a Message class where different id's for messages could be specified. The goal is to process messages according to id without relying on conditional structures like if-else and switch.
-
Turn message
id's into the Kafka topics. -
Route messages to specific topic based on it's
id. -
Subscribe consumer to desirable
id-topic and use it to process messages accordingly.
- Consumers must know ahead available message
id's.
However, since different id's assume different processing behaviour, which means such behaviour should be specified ahead. So the person implementing this behaviour would know about available id's and would have no problem implementing suitable consumer.
-
The main one (as I see now) is generalising
Messageclass. Which I believe can be done using Kafka Avro Serdes. -
Another one is to use Stream based Producer which would provide further convenience in terms of piping and processing of different messaging streams.
-
Launch Kafka
Inside the Kafka folder execute the following commands:bin/zookeeper-server-start.sh confizookeeper.properties bin/kafka-server-start.sh config/server.properties -
Produce some messages using
ProducerApplicationwhich could be found inorg.example.producerspackage. -
Consume these messages using
ConsumerApplicationwhich could be found inorg.example.consumers. -
There are two Consumer implementations - Streams based and vanilla
KafkaConsumerbased.Both implementations require base topic name, desirable message id to process, callback processing function, and serdes for the key and value of
ConsumerRecord(basicLongserde and customMessageSerdeare used as an example).