how to consume the json file from kafka using java, parse it using jackson and store it in DB via jdbc
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
add a comment |
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
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
add a comment |
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
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
database apache-kafka jackson
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 21 '18 at 13:28
Robin MoffattRobin Moffatt
6,7481329
6,7481329
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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