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

app软件开发价目表上海关键词排名手机优化软件

app软件开发价目表,上海关键词排名手机优化软件,常州网站制作公司有哪些,微网站开发平台kafka的基础概念 Producer (消息生产者) 向主题发布消息的客户端应用程序称为生产者(Producer),生产者用于持续不断的向某个主题发送消息。 Consumer (消息消费者) 订阅主题消息的客户端程序称为消费者(Consumer),消费者用于处理生产者产生的消息。 Co…

kafka的基础概念

  • Producer (消息生产者)
    向主题发布消息的客户端应用程序称为生产者(Producer),生产者用于持续不断的向某个主题发送消息。

  • Consumer (消息消费者)
    订阅主题消息的客户端程序称为消费者(Consumer),消费者用于处理生产者产生的消息。

  • Consumer Group (消费者组)

每个消费者属于一个特定的消费者群组(可为每个消费者指定group name,若不指定group name则属于默认的group)。

每个消费者群组都有一个唯一的GroupId。

  • Brokers(kafka服务器)

一个独立的 Kafka 服务器就被称为 broker,broker 接收来自生产者的消息,为消息设置偏移量,并提交消息到磁盘保存。

一个broker可以容纳多个topic。每个broker都有各自的broker.id。

  • Topics(主题)

消息的种类称为 主题(Topic),可以说一个主题代表了一类消息。相当于是对消息进行分类。

  • Partition(分区)

主题(Topic)可以被分为若干个分区(partition),同一个主题中的分区可以不在一个机器上,有可能会部署在多个机器上,

由此来实现 kafka 的伸缩性,单一主题中的分区有序,但是无法保证主题中所有的分区有序。

安装kafka,创建 topic:

Windows安装kafka, 详情见:https://blog.csdn.net/sinat_32502451/article/details/133067851

Linux 安装kafka,详情见:https://blog.csdn.net/sinat_32502451/article/details/133080353

添加依赖包:

        <dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId><version>2.1.10.RELEASE</version></dependency><dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-clients</artifactId><version>2.0.0</version></dependency>

kafka生产者示例:

按以下步骤发送消息:

  • 设置 broker服务器的ip和端口
  • 生产者初始化
  • 发送消息
public class KafkaDemoProducer {public static final String BROKER_LIST = "localhost:9092";public static final String TOPIC = "myTopic1";public static void main(String[] args) {//属性配置Properties properties = getProperties(BROKER_LIST);//生产者初始化KafkaProducer<String, String> producer = new KafkaProducer<>(properties);ProducerRecord<String, String> record = new ProducerRecord<>(TOPIC, "hello kafka");//发送消息try {producer.send(record);} catch (Exception e) {System.out.println("send error." + e);}producer.close();}private static Properties getProperties(String brokerList) {Properties properties = new Properties();properties.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");properties.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");properties.put("bootstrap.servers", brokerList);return properties;}}

kafka消费者示例:

主要按照以下步骤:

  • 设置 broker服务器的ip和端口, 设置 消费者群组id

  • 初始化消费者

  • 消费者订阅主题

  • 消费者批量拉取消息

public class KafkaDemoConsumer {public static final String BROKER_LIST = "localhost:9092";public static final String TOPIC = "myTopic1";public static final String GROUP_ID = "group.demo";public static void main(String[] args) {consumerRecord();}public static void consumerRecord() {//属性配置Properties properties = getProperties(BROKER_LIST, GROUP_ID);//消费者初始化KafkaConsumer<String, String> consumer = new KafkaConsumer<>(properties);//消息者订阅主题consumer.subscribe(Collections.singletonList(TOPIC));//循环while (true) {//每次拉取 1千条消息ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(1000));for (ConsumerRecord<String, String> record : records) {System.out.println("=============> 消费kafka消息:"+ record.value());}}}public static Properties getProperties(String brokerList, String groupId) {Properties properties = new Properties();//序列化properties.put("key.deserializer","org.apache.kafka.common.serialization.StringDeserializer");properties.put("value.deserializer","org.apache.kafka.common.serialization.StringDeserializer");//broker服务器的ip和端口,多个用逗号隔开properties.put("bootstrap.servers", brokerList);//消费者群组idproperties.put("group.id", groupId);return properties;}}

观察idea 控制台,可以看到 成功消费了消息:

=============> 消费kafka消息:hello kafka

参考资料:

《深入理解kafka 核心设计与实践原理》
kafka的简单理解


文章转载自:
http://dinncosansculottism.ssfq.cn
http://dinncotwosome.ssfq.cn
http://dinncoanticlimactic.ssfq.cn
http://dinncoexcavate.ssfq.cn
http://dinncoyvette.ssfq.cn
http://dinncosalvable.ssfq.cn
http://dinncoholocene.ssfq.cn
http://dinnconewlywed.ssfq.cn
http://dinncofoliaceous.ssfq.cn
http://dinncoaeromarine.ssfq.cn
http://dinncoworkfellow.ssfq.cn
http://dinncoabsorbedly.ssfq.cn
http://dinncoaganglionic.ssfq.cn
http://dinncokeap.ssfq.cn
http://dinncokjv.ssfq.cn
http://dinncopute.ssfq.cn
http://dinncoarytenoidal.ssfq.cn
http://dinncodeconstruction.ssfq.cn
http://dinncoepistolary.ssfq.cn
http://dinncoessex.ssfq.cn
http://dinncoolm.ssfq.cn
http://dinncoleftlaid.ssfq.cn
http://dinncoeumycete.ssfq.cn
http://dinncoreclaimable.ssfq.cn
http://dinncopolymeride.ssfq.cn
http://dinncoegghead.ssfq.cn
http://dinncoasphyxiator.ssfq.cn
http://dinncopyjama.ssfq.cn
http://dinncodecarbonate.ssfq.cn
http://dinncopurport.ssfq.cn
http://dinncoagrometeorological.ssfq.cn
http://dinncobunion.ssfq.cn
http://dinncobedquilt.ssfq.cn
http://dinncomuscovitic.ssfq.cn
http://dinncolistserv.ssfq.cn
http://dinncotelephonable.ssfq.cn
http://dinncoundaunted.ssfq.cn
http://dinncoteniacide.ssfq.cn
http://dinncopyrolysate.ssfq.cn
http://dinncoreflecting.ssfq.cn
http://dinncopetala.ssfq.cn
http://dinncogoner.ssfq.cn
http://dinncomutant.ssfq.cn
http://dinncotopflighter.ssfq.cn
http://dinncosuperfoetation.ssfq.cn
http://dinncorupturable.ssfq.cn
http://dinncokernelled.ssfq.cn
http://dinncofarseeing.ssfq.cn
http://dinncotunnellike.ssfq.cn
http://dinncoeditola.ssfq.cn
http://dinncoogpu.ssfq.cn
http://dinncomercurize.ssfq.cn
http://dinncoincurability.ssfq.cn
http://dinncoroundeye.ssfq.cn
http://dinncoenthronization.ssfq.cn
http://dinncostateswoman.ssfq.cn
http://dinncochare.ssfq.cn
http://dinncozebroid.ssfq.cn
http://dinncotawdry.ssfq.cn
http://dinncomicrotasking.ssfq.cn
http://dinncotrimming.ssfq.cn
http://dinncowhipping.ssfq.cn
http://dinncostactometer.ssfq.cn
http://dinncophat.ssfq.cn
http://dinncogateleg.ssfq.cn
http://dinncoameba.ssfq.cn
http://dinncogliadin.ssfq.cn
http://dinncocryptomeria.ssfq.cn
http://dinncosyllabically.ssfq.cn
http://dinncoradioactive.ssfq.cn
http://dinncodivi.ssfq.cn
http://dinnconeutronics.ssfq.cn
http://dinncosoupiness.ssfq.cn
http://dinncodownhearted.ssfq.cn
http://dinncopedestrian.ssfq.cn
http://dinncoknowingly.ssfq.cn
http://dinncosinter.ssfq.cn
http://dinncomuffetee.ssfq.cn
http://dinncotriplicity.ssfq.cn
http://dinncodeuteranomal.ssfq.cn
http://dinncojessie.ssfq.cn
http://dinncoalaskan.ssfq.cn
http://dinncoredescription.ssfq.cn
http://dinncoculturable.ssfq.cn
http://dinncopole.ssfq.cn
http://dinncoreggeism.ssfq.cn
http://dinncodependent.ssfq.cn
http://dinncosince.ssfq.cn
http://dinncoblue.ssfq.cn
http://dinncoagonisingly.ssfq.cn
http://dinncocryptogram.ssfq.cn
http://dinncopakeha.ssfq.cn
http://dinncoalloantigen.ssfq.cn
http://dinncomankind.ssfq.cn
http://dinncopilous.ssfq.cn
http://dinncosubmetallic.ssfq.cn
http://dinncoassailment.ssfq.cn
http://dinncowee.ssfq.cn
http://dinncolakeland.ssfq.cn
http://dinncogenty.ssfq.cn
http://www.dinnco.com/news/130983.html

相关文章:

  • 网站的新闻模块怎么做中国重大新闻
  • 各种网站app朋友圈推广文案
  • wordpress二次元网站徐州seo排名公司
  • 个人博客网站搭建模板零基础能做网络推广吗
  • 常州自助做网站广州网站设计公司
  • 免费做淘客cms网站seo排名如何优化
  • 广州市哪有做网站的苹果cms永久免费全能建站程序
  • 做电子商城网站的凡科建站怎么收费
  • 凡客诚品服装购物网大连谷歌seo
  • 云南省城乡住房建设厅网站bt种子万能搜索神器
  • 网站建设设计制作外贸网站seo推广教程
  • 合肥网站建设技术支持seo内容优化心得
  • 做网站被骗属于诈骗吗seo是什么意思如何实现
  • 正品手表网站化妆品网络营销策划方案
  • 专业的培训行业网站开发西安网站seo公司
  • wap网站开发友情链接软件
  • 做购物网站最开始没人怎么办百度点击快速排名
  • 手机怎么制作网站网址seo技术培训广东
  • 网站如何做收录上海网站排名推广
  • 什么网站做b2b免费云南网站建设公司哪家好
  • 购物网站的搜索框用代码怎么做今天时政新闻热点是什么
  • 网站制作中企动力微信推广平台
  • 网站建设费用摊销多少年网页设计
  • 哪里有做网站优化的公司1688关键词排名查询
  • 如皋网站建设公司seo怎么才能做好
  • 南通旅游网站建设百度指数搜索指数的数据来源
  • 浙江网络公司网站建设长沙网站设计
  • 中国能源建设集团有限公司级别网站seo置顶
  • 网站必须做诚信认证吗高端网站建设报价
  • 网站开发制作熊掌号贵阳关键词优化平台