java - kafka消息发送不出去
PHPz
PHPz 2017-04-18 10:26:29
0
2
377
import java.util.Properties; import net.sf.json.JSONObject; import kafka.javaapi.producer.Producer; import kafka.javaapi.producer.ProducerData; import kafka.producer.KeyedMessage; import kafka.producer.ProducerConfig; import kafka.serializer.StringEncoder; //利用线程池 调用类的静态函数发送消息 但是发布出去 不知道什么原因 public class SendOid2Kafka { private static Producer producer = createProducer(); public static void sendMessage2CMS(JSONObject message) { producer.send(new KeyedMessage("novel.review.topic", message)); System.out.println("send"); //执行不到这里 消息没发送出去 } private static Producer createProducer() { Properties properties = new Properties(); properties.put("zookeeper.connect","*"); properties.put("serializer.class", StringEncoder.class.getName()); properties.put("metadata.broker.list","*"); properties.put("zookeeper.session.timeout.ms", "15000"); return new Producer(new ProducerConfig(properties)); } }

改为发送String 就发送出去了
JSONObject就发送不出去

想发JSONObject怎么办???

PHPz
PHPz

学习是最好的投资!

reply all (2)
刘奇

Try converting JSONObject into JSON string.

    黄舟

    Use Alibaba’s JSONObject to convert it into a string and send it, and then the receiving end manually converts it into the class you want

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!