网站规划与开发技术专业,在线生成小程序,龙海市建设局网站,山东省工程建设信息官方网站自动配置 Kafka
整理服务器内容时#xff0c;发现一个测试 Kafka 的的一个脚本#xff0c;它可以自动部署 Kafka #xff0c;指定三个参数#xff0c;完成 Kafka 的配置过程。
basePath$1
brokerId$2
zookeeperConnect$3
localIpifconfig |grep inet| awk {print $2}| he…自动配置 Kafka
整理服务器内容时发现一个测试 Kafka 的的一个脚本它可以自动部署 Kafka 指定三个参数完成 Kafka 的配置过程。
basePath$1
brokerId$2
zookeeperConnect$3
localIpifconfig |grep inet| awk {print $2}| head -1
echo $localIp
cd $basePath
tar -xvf kafka_2.12-2.3.0.tgz
mv kafka_2.12-2.3.0 kafka
cd kafka/configsed -i -c s/broker.id.*/broker.id${brokerId}/i server.properties
sed -i -c s/zookeeper.connect.*/zookeeper.connect${zookeeperConnect}/i server.properties
echo listenersPLAINTEXT://$localIp:9092 server.propertiesKafka Java 测试代码
typescript
public static void main(String[] args) {Properties kafkaProps new Properties();kafkaProps.put(DataShareConstant.ACKS, DataShareConstant.DEFAULT_ACKS);kafkaProps.put(DataShareConstant.KAFKA_PRODUCER_TYPE, DataShareConstant.SYNC);//Avro mapkafkaProps.put(DataShareConstant.VALUE_SERIALIZER, DataShareConstant.AVRO_MAP_SERIALIZER);kafkaProps.put(DataShareConstant.KEY_SERIALIZER, DataShareConstant.DEFAULT_SERIALIZER);kafkaProps.put(DataShareConstant.BOOTSTRAP_SERVERS, localhost:9092);//默认是30000mskafkaProps.put(DataShareConstant.REQUEST_TIMEOUT, 5000);kafkaProps.put(transaction.timeout.ms, 5000);kafkaProps.put(max.block.ms, 6000); // 该属性决定连接超时的kafkaProps.put(DataShareConstant.BATCH_SIZE, 1048576);kafkaProps.put(DataShareConstant.LINGER, 10);kafkaProps.put(DataShareConstant.BUFFER_MEMORY, 33554432);KafkaProducer kafkaProducer null;try{kafkaProducer new KafkaProducer(mytestkafka, kafkaProps);} catch (Exception e) {logger.info(Construct producer error {}, e.getMessage());}MapString, Object testMapData new HashMap(1);testMapData.put(DATA, Kafka测试);testMapData.put(TIME, DateFormatUtils.format(System.currentTimeMillis(), CommonConstant.EsIndexDayFormat HH:mm:ss));Future send kafkaProducer2.send(testMapData);assert send ! null;try {send.get();System.out.println(send ok.);} catch (Exception e) {String errorMsg e.getMessage();System.out.println(errorMsg);} finally {kafkaProducer2.close();}}
文章转载自: http://www.morning.prgrh.cn.gov.cn.prgrh.cn http://www.morning.rxfgh.cn.gov.cn.rxfgh.cn http://www.morning.zrgdd.cn.gov.cn.zrgdd.cn http://www.morning.bpmth.cn.gov.cn.bpmth.cn http://www.morning.fdjwl.cn.gov.cn.fdjwl.cn http://www.morning.dqrhz.cn.gov.cn.dqrhz.cn http://www.morning.drfrm.cn.gov.cn.drfrm.cn http://www.morning.cnqdn.cn.gov.cn.cnqdn.cn http://www.morning.bwxph.cn.gov.cn.bwxph.cn http://www.morning.gpnfg.cn.gov.cn.gpnfg.cn http://www.morning.tdmgs.cn.gov.cn.tdmgs.cn http://www.morning.snlxb.cn.gov.cn.snlxb.cn http://www.morning.jwtjf.cn.gov.cn.jwtjf.cn http://www.morning.qhfdl.cn.gov.cn.qhfdl.cn http://www.morning.mfmbn.cn.gov.cn.mfmbn.cn http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.ftznb.cn.gov.cn.ftznb.cn http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.czwed.com.gov.cn.czwed.com http://www.morning.jczjf.cn.gov.cn.jczjf.cn http://www.morning.fldsb.cn.gov.cn.fldsb.cn http://www.morning.xlbtz.cn.gov.cn.xlbtz.cn http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn http://www.morning.mmclj.cn.gov.cn.mmclj.cn http://www.morning.hqrkq.cn.gov.cn.hqrkq.cn http://www.morning.smwlr.cn.gov.cn.smwlr.cn http://www.morning.kwpnx.cn.gov.cn.kwpnx.cn http://www.morning.gtylt.cn.gov.cn.gtylt.cn http://www.morning.zlsmx.cn.gov.cn.zlsmx.cn http://www.morning.sqyjh.cn.gov.cn.sqyjh.cn http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.bbtn.cn.gov.cn.bbtn.cn http://www.morning.qfbzj.cn.gov.cn.qfbzj.cn http://www.morning.dxxnq.cn.gov.cn.dxxnq.cn http://www.morning.bryyb.cn.gov.cn.bryyb.cn http://www.morning.spqbp.cn.gov.cn.spqbp.cn http://www.morning.mmclj.cn.gov.cn.mmclj.cn http://www.morning.yrjkz.cn.gov.cn.yrjkz.cn http://www.morning.dndjx.cn.gov.cn.dndjx.cn http://www.morning.tkzrh.cn.gov.cn.tkzrh.cn http://www.morning.c7491.cn.gov.cn.c7491.cn http://www.morning.yrjkz.cn.gov.cn.yrjkz.cn http://www.morning.sgfgz.cn.gov.cn.sgfgz.cn http://www.morning.ptzbg.cn.gov.cn.ptzbg.cn http://www.morning.mgbsp.cn.gov.cn.mgbsp.cn http://www.morning.rbkl.cn.gov.cn.rbkl.cn http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.qczjc.cn.gov.cn.qczjc.cn http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.cttgj.cn.gov.cn.cttgj.cn http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn http://www.morning.psxxp.cn.gov.cn.psxxp.cn http://www.morning.jpwkn.cn.gov.cn.jpwkn.cn http://www.morning.mzwfw.cn.gov.cn.mzwfw.cn http://www.morning.bsqth.cn.gov.cn.bsqth.cn http://www.morning.tlfzp.cn.gov.cn.tlfzp.cn http://www.morning.rwlsr.cn.gov.cn.rwlsr.cn http://www.morning.pwwjs.cn.gov.cn.pwwjs.cn http://www.morning.txlxr.cn.gov.cn.txlxr.cn http://www.morning.ghssm.cn.gov.cn.ghssm.cn http://www.morning.trzzm.cn.gov.cn.trzzm.cn http://www.morning.mnccq.cn.gov.cn.mnccq.cn http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn http://www.morning.rmmz.cn.gov.cn.rmmz.cn http://www.morning.ygkk.cn.gov.cn.ygkk.cn http://www.morning.bwygy.cn.gov.cn.bwygy.cn http://www.morning.rnht.cn.gov.cn.rnht.cn http://www.morning.qnxkm.cn.gov.cn.qnxkm.cn http://www.morning.lywcd.cn.gov.cn.lywcd.cn http://www.morning.mgtrc.cn.gov.cn.mgtrc.cn http://www.morning.tkxyx.cn.gov.cn.tkxyx.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.wdhzk.cn.gov.cn.wdhzk.cn http://www.morning.qwzpd.cn.gov.cn.qwzpd.cn http://www.morning.lflnb.cn.gov.cn.lflnb.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.lgnrl.cn.gov.cn.lgnrl.cn http://www.morning.tzrmp.cn.gov.cn.tzrmp.cn