前言
大家都在学习kafka,因为这确实非常有用,因为现在互联网时代,消息队列无处不在了。。下面直接上代码
消息生产者HelloKafkaProducer
package cn.enjoyedu.hellokafka;
import cn.enjoyedu.config.BusiConst;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.util.Properties;
/**
* @author dengcs
*
* 类说明:kafka生产者
*/
public class HelloKafkaProducer {
public static void main(String[] args) {
//TODO 生产者三个属性必须指定(broker地址清单、key和value的序列化器)
Properties properties = new Properties();
properties.put("bootstrap.servers","127.0.0.1:9092");
properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
KafkaProducer<String,String>