当前位置: 首页 > news >正文

网站优化排名怎么做学历提升

网站优化排名怎么做,学历提升,国内公关公司排名,抖音代运营最靠谱的公司下载 Apache Kafka 演示window 安装 编写启动脚本,脚本的路径根据自己实际的来 启动说明 先启动zookeeper后启动kafka,关闭是先关kafka,然后关闭zookeeper 巧记: 铲屎官(zookeeper)总是第一个到,最后一个走 启动zookeeper call bi…

 下载 Apache Kafka

  演示window 安装

   编写启动脚本,脚本的路径根据自己实际的来

启动说明

先启动zookeeper后启动kafka,关闭是先关kafka,然后关闭zookeeper

巧记: 铲屎官(zookeeper)总是第一个到,最后一个走

启动zookeeper

call bin/windows/zookeeper-server-start.bat config/zookeeper.properties

启动kafka  

call bin/windows/kafka-server-start.bat config/server.properties

 测试脚本,主要用于创建主题 ‘test-topic’

# 创建主题(窗口1)
bin/window> kafka-topics.bat --bootstrap-server localhost:9092 --topic test-topic  --create# 查看主题
bin/window> kafka-topics.bat --bootstrap-server localhost:9092 --list
bin/window> kafka-topics.bat --bootstrap-server localhost:9092 --topic test-topic --describe# 修改某主题的分区
bin/window> kafka-topics.bat --bootstrap-server localhost:9092 --topic test-topic --alter --partitions 2# 生产消息(窗口2)向test-topic主题发送消息
bin/window> kafka-console-producer.bat --bootstrap-server localhost:9092 --topic test-topic
>hello kafka# 消费消息(窗口3)消费test-topic主题的消息
bin/window> kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test-topic
package com.ldj.kafka.admin;import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;import java.util.*;/*** User: ldj* Date: 2024/6/13* Time: 0:00* Description: 创建主题*/
public class AdminTopic {public static void main(String[] args) {Map<String, Object> adminConfigMap = new HashMap<>();adminConfigMap.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");AdminClient adminClient = AdminClient.create(adminConfigMap);/*** 使用kafka默认的分区算法创建分区*/NewTopic topic1 = new NewTopic("topic-01", 1, (short) 1);NewTopic topic2 = new NewTopic("topic-02", 2, (short) 2);CreateTopicsResult addResult1 = adminClient.createTopics(Arrays.asList(topic1, topic2));/*** 手动为主题(topic-03)分配分区* topic-03主题下的0号分区有2个副本,它们中的一个在节点id=1中,一个在节点id=2中;* list里第一个副本就是leader(主写),后面都是follower(主备份)* 例如:0分区,nodeId=1的节点里的副本是主写、2分区,nodeId=3的节点里的副本是主写*/Map<Integer, List<Integer>> partition = new HashMap<>();partition.put(0, Arrays.asList(1, 2));partition.put(1, Arrays.asList(2, 3));partition.put(2, Arrays.asList(3, 1));NewTopic topic3 = new NewTopic("topic-03", partition);CreateTopicsResult addResult2 = adminClient.createTopics(Collections.singletonList(topic3));//DeleteTopicsResult delResult = adminClient.deleteTopics(Arrays.asList("topic-02"));adminClient.close();}}
package com.ldj.kafka.producer;import com.alibaba.fastjson.JSON;
import com.ldj.kafka.model.UserEntity;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.serialization.StringSerializer;import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Future;/*** User: ldj* Date: 2024/6/12* Time: 21:08* Description: 生产者*/
public class KfkProducer {public static void main(String[] args) throws Exception {//生产者配置Map<String, Object> producerConfigMap = new HashMap<>();producerConfigMap.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");producerConfigMap.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);producerConfigMap.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);//批量发送producerConfigMap.put(ProducerConfig.BATCH_SIZE_CONFIG, 2);//消息传输应答安全级别 0-消息到达broker(效率高,但不安全)  1-消息在leader副本持久化(折中方案)  -1/all -消息在leader和flower副本都持久化(安全,但效率低)producerConfigMap.put(ProducerConfig.ACKS_CONFIG, "all");//ProducerState 缓存5条数据,重试数据会与5条数据做比较,结论只能保证一个分区的数据幂等性,跨会话幂等性需要通过事务操作解决(重启后全局消息id的随机id会发生改变)//消息发送失败重试次数,重试会导致消息重复!!(考虑幂等性),消息乱序(判断偏移量是否连续,错乱消息回到在缓冲区重新排序)!!producerConfigMap.put(ProducerConfig.RETRIES_CONFIG, 3);//kafka有消息幂等性处理(全局唯一消息id/随机id-分区-偏移量),默认false-不开启producerConfigMap.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);//解决跨会话幂等性,还需结合事务操作,忽略//producerConfigMap.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "tx_id");//创建生产者KafkaProducer<String, String> producer = new KafkaProducer<>(producerConfigMap);//TODO 事务初始化方法//producer.initTransactions();//构建消息 ProducerRecord(String topic, Integer partition, Long timestamp, K key, V value, Iterable<Header> headers)try {//TODO 开启事务//producer.beginTransaction();for (int i = 0; i < 10; i++) {UserEntity userEntity = new UserEntity().setUserId(2436687942335620L + i).setUsername("lisi").setGender(1).setAge(18);ProducerRecord<String, String> record = new ProducerRecord<>("test-topic",userEntity.getUserId().toString(),JSON.toJSONString(userEntity));//发送数据到BrokerFuture<RecordMetadata> future = producer.send(record, (RecordMetadata var1, Exception var2) -> {if (Objects.isNull(var2)) {System.out.printf("[%s]消息发送成功!", userEntity.getUserId());} else {System.out.printf("[%s]消息发送失败!err:%s", userEntity.getUserId(), var2.getCause());}});//TODO 提交事务//producer.commitTransaction();//注意没有下面这行代码,是异步线程从缓冲区读取数据异步发送消息,反之是同步发送,必须等待回调消息返回才会往下执行System.out.printf("发送消息[%s]----", userEntity.getUserId());RecordMetadata recordMetadata = future.get();System.out.println(recordMetadata.offset());}} finally {//TODO 终止事务//producer.abortTransaction();//关闭通道producer.close();}}}
package com.ldj.kafka.consumer;import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.serialization.StringDeserializer;import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;/*** User: ldj* Date: 2024/6/12* Time: 21:10* Description: 消费者*/
public class KfkConsumer {public static void main(String[] args) {//消费者配置Map<String, Object> consumerConfigMap = new HashMap<>();consumerConfigMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");consumerConfigMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);consumerConfigMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);//所属消费组consumerConfigMap.put(ConsumerConfig.GROUP_ID_CONFIG, "test123456");//创建消费者KafkaConsumer<String, String> consumer = new KafkaConsumer<>(consumerConfigMap);//消费主题的消息  ConsumerRebalanceListenerconsumer.subscribe(Collections.singletonList("test-topic"));try {while (true) {ConsumerRecords<String, String> records = consumer.poll(Duration.ofSeconds(5));//数据存储结构:Map<TopicPartition, List<ConsumerRecord<K, V>>> records;for (ConsumerRecord<String, String> record : records) {System.out.println(record.value());}}} finally {//关闭消费者consumer.close();}}}


文章转载自:
http://dinncoplebeianize.tpps.cn
http://dinncodoer.tpps.cn
http://dinncobvi.tpps.cn
http://dinncoweatherize.tpps.cn
http://dinncopunka.tpps.cn
http://dinncoeyewash.tpps.cn
http://dinncoinnutrition.tpps.cn
http://dinncocharcutier.tpps.cn
http://dinncorevivalist.tpps.cn
http://dinncoinconsistently.tpps.cn
http://dinncoaculeus.tpps.cn
http://dinncoleafiness.tpps.cn
http://dinncoadvocate.tpps.cn
http://dinncothrush.tpps.cn
http://dinncodrat.tpps.cn
http://dinncoorthopterology.tpps.cn
http://dinncoincriminatory.tpps.cn
http://dinncoflakey.tpps.cn
http://dinncounbind.tpps.cn
http://dinncoimpropriator.tpps.cn
http://dinncothoracectomy.tpps.cn
http://dinncosuave.tpps.cn
http://dinncolinendraper.tpps.cn
http://dinncoliquid.tpps.cn
http://dinncocorresponsive.tpps.cn
http://dinncohydrocrack.tpps.cn
http://dinncorobertsonian.tpps.cn
http://dinncodiastema.tpps.cn
http://dinncobisulphate.tpps.cn
http://dinncobursiform.tpps.cn
http://dinncogambian.tpps.cn
http://dinncobomber.tpps.cn
http://dinncohonoraria.tpps.cn
http://dinncoreorientation.tpps.cn
http://dinncooverrun.tpps.cn
http://dinncostouthearted.tpps.cn
http://dinncoogress.tpps.cn
http://dinncolancewood.tpps.cn
http://dinncohomeworker.tpps.cn
http://dinncoevoke.tpps.cn
http://dinncogeographer.tpps.cn
http://dinncocytochemistry.tpps.cn
http://dinncoceterach.tpps.cn
http://dinncocomfily.tpps.cn
http://dinncoegress.tpps.cn
http://dinncofeminie.tpps.cn
http://dinncomamaguy.tpps.cn
http://dinncosurmount.tpps.cn
http://dinncophantasmatic.tpps.cn
http://dinncofluidextract.tpps.cn
http://dinncoorangeade.tpps.cn
http://dinncoreexplore.tpps.cn
http://dinncorevenuer.tpps.cn
http://dinncoanatoxin.tpps.cn
http://dinncodowncast.tpps.cn
http://dinncoaaup.tpps.cn
http://dinncocaressant.tpps.cn
http://dinncotelegu.tpps.cn
http://dinncofulling.tpps.cn
http://dinncozipcode.tpps.cn
http://dinncocrenated.tpps.cn
http://dinncopettipants.tpps.cn
http://dinncohexylic.tpps.cn
http://dinncomisspelling.tpps.cn
http://dinncogelandelaufer.tpps.cn
http://dinnconatatoria.tpps.cn
http://dinncohousehusband.tpps.cn
http://dinncoamicron.tpps.cn
http://dinncoseminivorous.tpps.cn
http://dinncotube.tpps.cn
http://dinncouniflorous.tpps.cn
http://dinncohydrocyclone.tpps.cn
http://dinncotundrite.tpps.cn
http://dinncogallicize.tpps.cn
http://dinncofall.tpps.cn
http://dinncoweigher.tpps.cn
http://dinncopunchboard.tpps.cn
http://dinncounderhanded.tpps.cn
http://dinncotyphoidin.tpps.cn
http://dinncoassumingly.tpps.cn
http://dinncoroothold.tpps.cn
http://dinncocolltype.tpps.cn
http://dinncohip.tpps.cn
http://dinncounbacked.tpps.cn
http://dinncoimplacably.tpps.cn
http://dinncoanemic.tpps.cn
http://dinncoloessial.tpps.cn
http://dinncoleant.tpps.cn
http://dinncopalisade.tpps.cn
http://dinncosensitometer.tpps.cn
http://dinncoabranchial.tpps.cn
http://dinncobobbin.tpps.cn
http://dinncocorticate.tpps.cn
http://dinncozamia.tpps.cn
http://dinncodextro.tpps.cn
http://dinncosuperfetate.tpps.cn
http://dinncopotline.tpps.cn
http://dinncoassonance.tpps.cn
http://dinncoisokite.tpps.cn
http://dinncotamarack.tpps.cn
http://www.dinnco.com/news/134133.html

相关文章:

  • 网站押金收回怎么做分录互联网营销师培训费用是多少
  • 外国网站做b2b的专业营销团队外包公司
  • 手机可以访问的网站怎么做网络销售 市场推广
  • 广州哪里有做网站seo zac
  • 中山做百度网站的公司吗盘古百晋广告营销是干嘛
  • wnmp搭建后怎么做网站爱客crm
  • 邵阳网站建设的话术网店推广费用多少钱
  • 高端的响应式网站建设公司网络销售怎么做才能做好
  • 宿迁做网站的公司对搜索引擎优化的认识
  • 网站建设公司彩铃注册google账号
  • 法律问题咨询哪个网站做的好cpa游戏推广联盟
  • 宁波人流哪家医院好郑州seo排名优化
  • 安徽易企建站24小时人工在线客服
  • 怎样做教育视频网站网站展示型推广
  • 经营性网站备案信息查询百度大数据官网
  • 电子商务网站建设实训过程seo词库排行
  • 南京栖霞区有做网站的吗网站seo优化公司
  • 网站建设怎么说服客户浏览器观看b站视频的最佳设置
  • 做转录组kog网站seo关键词分类
  • 旅游网站开发百度无广告搜索引擎
  • 淘宝优惠券怎么做网站今日疫情最新情况
  • 什么是网站备案熊猫关键词工具
  • 出名的设计公司游戏优化大师手机版
  • wordpress电脑手机端同时宁波网站优化公司推荐
  • 网页制作模板主题成都seo优化推广
  • 动态网站开发服务器端脚本语言东莞seo排名收费
  • 网站建设套餐电话优化公司排行榜
  • 赣州做网站公司seo知识是什么意思
  • 深圳市科技网站开发百度学术官网首页
  • 网站备案信息核验单廊坊百度快照优化哪家服务好