how to consume the json file from kafka using java, parse it using jackson and store it in DB via jdbc












-1















I have written a code to consume the message from kafka, but i want to see an example how the consumed kafka message is converted to java object using jackson and then store it in database for processing the data.










share|improve this question

























  • Not clear what database you are using... Please don't try to write a consumer yourself to handle this. If you want to simply store JSON messages into a JDBC compatible database, I suggest you use Kafka Connect.

    – cricket_007
    Nov 20 '18 at 15:23













  • @cricket_007 Thanks for the reply. I am using SAP HANA DB. You are right, we can use kafka connect to directly store the JSON messages in database, but my requirement in my use case is to consume the kafka messsage, convert the JSON string to java objects using jackson and write to DB. Can you please tell me how I can convert the consumed kafka JSON?

    – Aleena
    Nov 21 '18 at 8:31











  • Again, doing this yourself and managing offsets and failure scenarios is not going to work out well. Connect does exactly you're requirement, and requires no code on your part, only config files, why not use it?... And if you want to continue down this path, Kafka already provides a JSONDeserializer class for a Consumer property. Have you tried using either it, or a StringDeserializer, then parsing the string in the consumer?

    – cricket_007
    Nov 21 '18 at 14:47


















-1















I have written a code to consume the message from kafka, but i want to see an example how the consumed kafka message is converted to java object using jackson and then store it in database for processing the data.










share|improve this question

























  • Not clear what database you are using... Please don't try to write a consumer yourself to handle this. If you want to simply store JSON messages into a JDBC compatible database, I suggest you use Kafka Connect.

    – cricket_007
    Nov 20 '18 at 15:23













  • @cricket_007 Thanks for the reply. I am using SAP HANA DB. You are right, we can use kafka connect to directly store the JSON messages in database, but my requirement in my use case is to consume the kafka messsage, convert the JSON string to java objects using jackson and write to DB. Can you please tell me how I can convert the consumed kafka JSON?

    – Aleena
    Nov 21 '18 at 8:31











  • Again, doing this yourself and managing offsets and failure scenarios is not going to work out well. Connect does exactly you're requirement, and requires no code on your part, only config files, why not use it?... And if you want to continue down this path, Kafka already provides a JSONDeserializer class for a Consumer property. Have you tried using either it, or a StringDeserializer, then parsing the string in the consumer?

    – cricket_007
    Nov 21 '18 at 14:47
















-1












-1








-1








I have written a code to consume the message from kafka, but i want to see an example how the consumed kafka message is converted to java object using jackson and then store it in database for processing the data.










share|improve this question
















I have written a code to consume the message from kafka, but i want to see an example how the consumed kafka message is converted to java object using jackson and then store it in database for processing the data.







database apache-kafka jackson






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 15:22









cricket_007

80.8k1142110




80.8k1142110










asked Nov 20 '18 at 11:14









AleenaAleena

1




1













  • Not clear what database you are using... Please don't try to write a consumer yourself to handle this. If you want to simply store JSON messages into a JDBC compatible database, I suggest you use Kafka Connect.

    – cricket_007
    Nov 20 '18 at 15:23













  • @cricket_007 Thanks for the reply. I am using SAP HANA DB. You are right, we can use kafka connect to directly store the JSON messages in database, but my requirement in my use case is to consume the kafka messsage, convert the JSON string to java objects using jackson and write to DB. Can you please tell me how I can convert the consumed kafka JSON?

    – Aleena
    Nov 21 '18 at 8:31











  • Again, doing this yourself and managing offsets and failure scenarios is not going to work out well. Connect does exactly you're requirement, and requires no code on your part, only config files, why not use it?... And if you want to continue down this path, Kafka already provides a JSONDeserializer class for a Consumer property. Have you tried using either it, or a StringDeserializer, then parsing the string in the consumer?

    – cricket_007
    Nov 21 '18 at 14:47





















  • Not clear what database you are using... Please don't try to write a consumer yourself to handle this. If you want to simply store JSON messages into a JDBC compatible database, I suggest you use Kafka Connect.

    – cricket_007
    Nov 20 '18 at 15:23













  • @cricket_007 Thanks for the reply. I am using SAP HANA DB. You are right, we can use kafka connect to directly store the JSON messages in database, but my requirement in my use case is to consume the kafka messsage, convert the JSON string to java objects using jackson and write to DB. Can you please tell me how I can convert the consumed kafka JSON?

    – Aleena
    Nov 21 '18 at 8:31











  • Again, doing this yourself and managing offsets and failure scenarios is not going to work out well. Connect does exactly you're requirement, and requires no code on your part, only config files, why not use it?... And if you want to continue down this path, Kafka already provides a JSONDeserializer class for a Consumer property. Have you tried using either it, or a StringDeserializer, then parsing the string in the consumer?

    – cricket_007
    Nov 21 '18 at 14:47



















Not clear what database you are using... Please don't try to write a consumer yourself to handle this. If you want to simply store JSON messages into a JDBC compatible database, I suggest you use Kafka Connect.

– cricket_007
Nov 20 '18 at 15:23







Not clear what database you are using... Please don't try to write a consumer yourself to handle this. If you want to simply store JSON messages into a JDBC compatible database, I suggest you use Kafka Connect.

– cricket_007
Nov 20 '18 at 15:23















@cricket_007 Thanks for the reply. I am using SAP HANA DB. You are right, we can use kafka connect to directly store the JSON messages in database, but my requirement in my use case is to consume the kafka messsage, convert the JSON string to java objects using jackson and write to DB. Can you please tell me how I can convert the consumed kafka JSON?

– Aleena
Nov 21 '18 at 8:31





@cricket_007 Thanks for the reply. I am using SAP HANA DB. You are right, we can use kafka connect to directly store the JSON messages in database, but my requirement in my use case is to consume the kafka messsage, convert the JSON string to java objects using jackson and write to DB. Can you please tell me how I can convert the consumed kafka JSON?

– Aleena
Nov 21 '18 at 8:31













Again, doing this yourself and managing offsets and failure scenarios is not going to work out well. Connect does exactly you're requirement, and requires no code on your part, only config files, why not use it?... And if you want to continue down this path, Kafka already provides a JSONDeserializer class for a Consumer property. Have you tried using either it, or a StringDeserializer, then parsing the string in the consumer?

– cricket_007
Nov 21 '18 at 14:47







Again, doing this yourself and managing offsets and failure scenarios is not going to work out well. Connect does exactly you're requirement, and requires no code on your part, only config files, why not use it?... And if you want to continue down this path, Kafka already provides a JSONDeserializer class for a Consumer property. Have you tried using either it, or a StringDeserializer, then parsing the string in the consumer?

– cricket_007
Nov 21 '18 at 14:47














1 Answer
1






active

oldest

votes


















0














Kafka Connect will do all of this for you. You don't need to be writing any Java code, or converting JSON. Use the kafka-connect-jdbc sink to stream the data to the database, and use the JsonConverter. You can read more about converters in Kafka Connect here.



If you want to process the message beforehand, you can use stream processing options such as Kafka Streams, KSQL, Spark Streaming, etc etc. These can then write to a second Kafka topic. For writing to a database (or anywhere else), simply use Kafka Connect.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391792%2fhow-to-consume-the-json-file-from-kafka-using-java-parse-it-using-jackson-and-s%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Kafka Connect will do all of this for you. You don't need to be writing any Java code, or converting JSON. Use the kafka-connect-jdbc sink to stream the data to the database, and use the JsonConverter. You can read more about converters in Kafka Connect here.



    If you want to process the message beforehand, you can use stream processing options such as Kafka Streams, KSQL, Spark Streaming, etc etc. These can then write to a second Kafka topic. For writing to a database (or anywhere else), simply use Kafka Connect.






    share|improve this answer




























      0














      Kafka Connect will do all of this for you. You don't need to be writing any Java code, or converting JSON. Use the kafka-connect-jdbc sink to stream the data to the database, and use the JsonConverter. You can read more about converters in Kafka Connect here.



      If you want to process the message beforehand, you can use stream processing options such as Kafka Streams, KSQL, Spark Streaming, etc etc. These can then write to a second Kafka topic. For writing to a database (or anywhere else), simply use Kafka Connect.






      share|improve this answer


























        0












        0








        0







        Kafka Connect will do all of this for you. You don't need to be writing any Java code, or converting JSON. Use the kafka-connect-jdbc sink to stream the data to the database, and use the JsonConverter. You can read more about converters in Kafka Connect here.



        If you want to process the message beforehand, you can use stream processing options such as Kafka Streams, KSQL, Spark Streaming, etc etc. These can then write to a second Kafka topic. For writing to a database (or anywhere else), simply use Kafka Connect.






        share|improve this answer













        Kafka Connect will do all of this for you. You don't need to be writing any Java code, or converting JSON. Use the kafka-connect-jdbc sink to stream the data to the database, and use the JsonConverter. You can read more about converters in Kafka Connect here.



        If you want to process the message beforehand, you can use stream processing options such as Kafka Streams, KSQL, Spark Streaming, etc etc. These can then write to a second Kafka topic. For writing to a database (or anywhere else), simply use Kafka Connect.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 13:28









        Robin MoffattRobin Moffatt

        6,7481329




        6,7481329






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391792%2fhow-to-consume-the-json-file-from-kafka-using-java-parse-it-using-jackson-and-s%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory