@@ -16,37 +16,36 @@ public class ProducerImpl implements Producer {
1616
1717 public ProducerImpl () {
1818 properties = new Properties ();
19- properties .put ("queue.enqueue.timeout.ms" , -1 );
20- properties .put ("enable.idempotence" , true );
2119 properties .put ("bootstrap.servers" , "localhost:9092" );
22- properties .put ("transactional.id" , "transactional_1" );
23- properties .put ("acks" , "all" );
24- properties .put ("retries" , "3" );
25- properties .put ("max.in.flight.requests.per.connection" , 1 );
20+ // properties.put("queue.enqueue.timeout.ms", -1);
21+ // properties.put("enable.idempotence", true);
22+ // properties.put("transactional.id", "transactional_1");
23+ // properties.put("acks", "all");
24+ // properties.put("retries", "3");
25+ // properties.put("max.in.flight.requests.per.connection", 1);
2626 properties .put ("key.serializer" , "org.apache.kafka.common.serialization.StringSerializer" );
2727 properties .put ("value.serializer" , "org.apache.kafka.common.serialization.StringSerializer" );
2828 producer = new KafkaProducer <String , String >(properties );
29- producer .initTransactions ();
29+ // producer.initTransactions();
3030 }
3131
3232 @ Override
3333 public void send (Order order ) {
34- Object json = JSON .toJSON (order );
3534 try {
36- producer .beginTransaction ();
37- ProducerRecord record = new ProducerRecord (topic , order .getId ().toString (), json . toString ( ));
35+ // producer.beginTransaction();
36+ ProducerRecord record = new ProducerRecord (topic , order .getId ().toString (), JSON . toJSONString ( order ));
3837 producer .send (record , (metadata , exception ) -> {
39- if (exception != null ) {
40- producer .abortTransaction ();
41- throw new KafkaException (exception .getMessage () + " , data: " + record );
42- }
38+ // if (exception != null) {
39+ // producer.abortTransaction();
40+ // throw new KafkaException(exception.getMessage() + " , data: " + record);
41+ // }
4342 });
44- producer .commitTransaction ();
43+ // producer.commitTransaction();
4544
4645 } catch (Throwable e ) {
47- producer .abortTransaction ();
46+ // producer.abortTransaction();
4847 }
49- System .out .println ("************" + json + "************" );
48+ // System.out.println("************" + json + "************");
5049 }
5150
5251 @ Override
0 commit comments