I want to produce a message into kafka topic. That message should have this pattern:
{"targetFileInfo":{"path":"2018-05-07-10/row01-small-01.txt.ready"}}
I know that is a json pattern, so how can i convert that json in String?
I use a maven project, so which dependencies are needed to use
String stringData = JSON.stringify({"targetFileInfo":{"path":"2018-05-07-10/row01-small-01.txt.ready"}});
So I think it is better don't convert Json to string and send indeed that massage into kafka topic.
My Code is like that, it can send a String but i don't know how i can modify my code to send the massage above. maybe you can help me.
Producer<String, String> producer = null;
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092");
props.put("acks", "all");
props.put("retries", 0);
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producer = new KafkaProducer<>(props);
String msg = "welcome";
producer.send(new ProducerRecord<String, String>("event", msg));
producer.close();