java - Spring Kafka Custom Deserializer -


i following steps listed in link create customer deserializer. message receive kafka has plain text "log message -" before json string.i want deserializer ignore string , parse json data. there way it?

application

@springbootapplication public class transactionauditserviceapplication {      public static void main(string[] args) throws interruptedexception {         new springapplicationbuilder(transactionauditserviceapplication.class).web(false).run(args);     }      @bean     public messagelistener messagelistener() {         return new messagelistener();     }      public static class messagelistener {          @kafkalistener(topics = "ctp_verbose", containerfactory = "kafkalistenercontainerfactory")         public void listen(@payload concisemessage message,                    @header(kafkaheaders.received_partition_id) int partition) {             system.out.println("received messasge in group foo: " + message.getstringvalue("traceid") + " partion " + partition);         }     } } 

consumerconfig

@enablekafka @configuration public class kafkaconsumerconfig {      @value(value = "${kafka.bootstrapaddress:localhost:9092}")     private string bootstrapaddress;      @value(value = "${groupid:audit}")     private string groupid;      @bean     public consumerfactory<string, concisemessage> consumerfactory() {         map<string, object> props = new hashmap<>();         props.put(consumerconfig.bootstrap_servers_config, bootstrapaddress);         props.put(consumerconfig.group_id_config, groupid);         return new defaultkafkaconsumerfactory<>(props, new stringdeserializer(), new jsondeserializer<>(concisemessage.class));     }      @bean     public concurrentkafkalistenercontainerfactory<string, concisemessage> kafkalistenercontainerfactory() {          concurrentkafkalistenercontainerfactory<string, concisemessage> factory = new concurrentkafkalistenercontainerfactory<>();         factory.setconsumerfactory(consumerfactory());         return factory;     } } 

by writing line new jsondeserializer<>(concisemessage.class), telling kafka want convert message concisemessage type. so, doesn't make custom deserializer. fix problem have come own implementation of deserializer has logic strip text "log message -".


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -