Sending message to kafka using TIBCO

This is the java code that I am using in java code activity of the TIBCO BW to publish the message on the Kafka queue but I am getting errors repeatedly. Kindly help me.

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;

import org.apache.kafka.clients.producer.Producer;

import org.apache.kafka.clients.producer.ProducerRecord;



public class Publisher {

    public static void main(String[] a) {

         Properties props = new Properties();

         props.put("bootstrap.servers", "localhost:9092");

         props.put("acks", "all");

         props.put("retries", 0);

         props.put("batch.size", 16384);

         props.put("linger.ms", 1);

         props.put("buffer.memory", 33554432);

         props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");

         props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

         Producer<String, String> producer = new KafkaProducer<>(props);

         for(int i = 0; i < 100; i++)

             producer.send(new ProducerRecord<String, String>("test", Integer.toString(i), Integer.toString(i)));

         producer.close();

         

    }

}

 

 

1 Comment

Thanks for posting this. Did you test and validate this code? Were there any updates following your testing?

jdefendis - Sep 25, 2017 - 10:49am
+ Add a Comment

(3) Answers

Login