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

单页网站模板修改外贸网站建设案例

单页网站模板修改,外贸网站建设案例,高德导航怎么看街景地图,自己做网站卖东西需要交税吗SpringBoot集成Kafka实现消息发送和接收。 一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者 君子之学贵一,一则明,明则有功。 一、Kafka 简介 Kafka 是由 Apache 软件基金会开发的一个开源流处理平台,最初由 Link…

SpringBoot集成Kafka实现消息发送和接收。

  • 一、Kafka 简介
  • 二、Kafka 功能
  • 三、POM依赖
  • 四、配置文件
  • 五、生产者
  • 六、消费者

君子之学贵一,一则明,明则有功

一、Kafka 简介

Kafka 是由 Apache 软件基金会开发的一个开源流处理平台,最初由 LinkedIn 公司开发,并于 2011 年开源。它是一种高吞吐量的分布式发布 - 订阅消息系统,以可持久化、高吞吐、低延迟、高容错等特性而著称。
Kafka 主要由生产者(Producer)、消费者(Consumer)、主题(Topic)、分区(Partition)和代理(Broker)等组件构成。生产者负责将数据发送到 Kafka 集群,消费者从集群中读取数据。主题是一种逻辑上的分类,数据被发送到特定的主题。每个主题又可以划分为多个分区,以实现数据的并行处理和提高系统的可扩展性。代理则是 Kafka 集群中的服务器节点,负责接收和存储生产者发送的数据,并为消费者提供数据读取服务。

二、Kafka 功能

消息队列功能:Kafka 可以作为消息队列使用,在应用程序之间传递消息。生产者将消息发送到主题,不同的消费者可以从主题中订阅并消费消息,实现应用程序解耦。例如,在电商系统中,订单生成模块可以将订单消息发送到 Kafka 主题,后续的库存管理、物流配送等模块可以从该主题消费订单消息,各自独立处理,降低模块间的耦合度。
数据存储功能:Kafka 具有持久化存储能力,它将消息数据存储在磁盘上,并且通过多副本机制保证数据的可靠性。即使某个节点出现故障,数据也不会丢失。这种特性使得 Kafka 不仅可以作为消息队列,还能用于数据的长期存储和备份,例如用于存储系统的操作日志,方便后续的数据分析和故障排查。
流处理功能:Kafka 可以与流处理框架(如 Apache Flink、Spark Streaming 等)集成,对实时数据流进行处理。通过将实时数据发送到 Kafka 主题,流处理框架可以从主题中读取数据并进行实时计算、分析和转换。例如,在实时监控系统中,通过 Kafka 收集服务器的性能指标数据,然后使用流处理框架对这些数据进行实时分析,及时发现性能异常并发出警报。

三、POM依赖

    <!-- kafka--><dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId><version>2.8.11</version></dependency>

四、配置文件

spring:# Kafka 配置kafka:# Kafka 服务器地址和端口 代理地址,可以多个bootstrap-servers: IP:9092# 生产者配置producer:# 发送失败时的重试次数retries: 3# 每次批量发送消息的数量,调整为较小值batch-size: 1# 生产者缓冲区大小buffer-memory: 33554432# 消息 key 的序列化器,将 key 序列化为字节数组key-serializer: org.apache.kafka.common.serialization.StringSerializer# 消息 value 的序列化器,将消息体序列化为字节数组value-serializer: org.apache.kafka.common.serialization.StringSerializer# 消费者配置consumer:# 当没有初始偏移量或当前偏移量不存在时,从最早的消息开始消费auto-offset-reset: earliest# 是否自动提交偏移量enable-auto-commit: true# 自动提交偏移量的时间间隔(毫秒),延长自动提交时间间隔auto-commit-interval: 1000# 消息 key 的反序列化器,将字节数组反序列化为 keykey-deserializer: org.apache.kafka.common.serialization.StringDeserializer# 消息 value 的反序列化器,将字节数组反序列化为消息体value-deserializer: org.apache.kafka.common.serialization.StringDeserializer

五、生产者


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;/*** 生产者** @author chenlei*/
@Slf4j
@Component
public class KafkaProducer {/*** KafkaTemplate*/@Autowiredprivate KafkaTemplate<String, String> kafkaTemplate;/*** 发送消息到指定的 Kafka 主题,并可指定分组信息** @param topic   消息要发送到的 Kafka 主题* @param message 要发送的消息内容*/public void sendMessage(String topic, String message) {// 使用 KafkaTemplate 发送消息,将消息发送到指定的主题ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topic, message);future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {@Overridepublic void onSuccess(SendResult<String, String> result) {// 消息发送成功后的处理逻辑,可根据需要添加log.info("已发送消息=[" + message + "],其偏移量=[" + result.getRecordMetadata().offset() + "]");}@Overridepublic void onFailure(Throwable ex) {// 消息发送失败后的处理逻辑,使用日志记录异常log.error("发送消息=[" + message + "] 失败", ex);}});}
}

六、消费者

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;/*** @author 消费者* chenlei*/
@Slf4j
@Component
public class KafkaConsumer {/*** 监听 Kafka 主题方法。** @param record 从 Kafka 接收到的 ConsumerRecord,包含消息的键值对*/@KafkaListener(topics = {"topic"}, groupId = "consumer.group-id", concurrency = "5")public void listen(ConsumerRecord<?, ?> record) {// 打印接收到的消息的详细信息log.info("接收到 Kafka 消息: 主题 = {}, 分区 = {}, 偏移量 = {}, 键 = {}, 值 = {}",record.topic(), record.partition(), record.offset(), record.key(), record.value());}
}

文章转载自:
http://dinncoelegancy.tpps.cn
http://dinncopodsol.tpps.cn
http://dinncoalbert.tpps.cn
http://dinncogriselda.tpps.cn
http://dinncoerie.tpps.cn
http://dinncosinge.tpps.cn
http://dinncoimmunology.tpps.cn
http://dinncospeechwriter.tpps.cn
http://dinncopersonage.tpps.cn
http://dinncoracemate.tpps.cn
http://dinncomodacrylic.tpps.cn
http://dinncoandes.tpps.cn
http://dinncooutbrave.tpps.cn
http://dinncoreflex.tpps.cn
http://dinncolaban.tpps.cn
http://dinncoextemporal.tpps.cn
http://dinncoestop.tpps.cn
http://dinncohealingly.tpps.cn
http://dinncopalazzos.tpps.cn
http://dinncoleafleteer.tpps.cn
http://dinncoequivalence.tpps.cn
http://dinncoextraconstitutional.tpps.cn
http://dinncowashiness.tpps.cn
http://dinncodetruncation.tpps.cn
http://dinncogainable.tpps.cn
http://dinncoperidium.tpps.cn
http://dinncocanalization.tpps.cn
http://dinncopalish.tpps.cn
http://dinncodeccan.tpps.cn
http://dinncomuntz.tpps.cn
http://dinncosenegalese.tpps.cn
http://dinncogralloch.tpps.cn
http://dinncosuperfluity.tpps.cn
http://dinncorhetor.tpps.cn
http://dinncopopshop.tpps.cn
http://dinnconeedlecase.tpps.cn
http://dinncokonak.tpps.cn
http://dinncoonward.tpps.cn
http://dinncograceless.tpps.cn
http://dinncohdd.tpps.cn
http://dinncoyeomenry.tpps.cn
http://dinncotartarly.tpps.cn
http://dinncouncolike.tpps.cn
http://dinncoeai.tpps.cn
http://dinncoauthigenic.tpps.cn
http://dinncoeaprom.tpps.cn
http://dinnconegrillo.tpps.cn
http://dinncobucaramanga.tpps.cn
http://dinncogallonage.tpps.cn
http://dinncosuffocate.tpps.cn
http://dinncodumbbell.tpps.cn
http://dinncoyell.tpps.cn
http://dinncoblc.tpps.cn
http://dinncoursine.tpps.cn
http://dinncooilcan.tpps.cn
http://dinncodahabeeyah.tpps.cn
http://dinncotrowbridge.tpps.cn
http://dinncoshamois.tpps.cn
http://dinncoeelfare.tpps.cn
http://dinncoscrewball.tpps.cn
http://dinncocaution.tpps.cn
http://dinncophs.tpps.cn
http://dinncoautocritcal.tpps.cn
http://dinncotireless.tpps.cn
http://dinncopreservice.tpps.cn
http://dinncokanzu.tpps.cn
http://dinncoironing.tpps.cn
http://dinncofolliculitis.tpps.cn
http://dinncoaufwuch.tpps.cn
http://dinncoprotean.tpps.cn
http://dinncoturbosphere.tpps.cn
http://dinncoinkwell.tpps.cn
http://dinnconautilus.tpps.cn
http://dinncohistolysis.tpps.cn
http://dinncotrifoliate.tpps.cn
http://dinncosyria.tpps.cn
http://dinncoskyscrape.tpps.cn
http://dinncohusk.tpps.cn
http://dinncostalwart.tpps.cn
http://dinncounzip.tpps.cn
http://dinncoeagerness.tpps.cn
http://dinncooriginality.tpps.cn
http://dinncofeignedly.tpps.cn
http://dinncoimpoliteness.tpps.cn
http://dinncopainterly.tpps.cn
http://dinncopinfall.tpps.cn
http://dinncosynecdoche.tpps.cn
http://dinncoawestruck.tpps.cn
http://dinncodesecrate.tpps.cn
http://dinncoepigynous.tpps.cn
http://dinncosuction.tpps.cn
http://dinncosymphysis.tpps.cn
http://dinncononuple.tpps.cn
http://dinncovihara.tpps.cn
http://dinncohomolecithal.tpps.cn
http://dinncopbs.tpps.cn
http://dinncotrinodal.tpps.cn
http://dinncokorean.tpps.cn
http://dinncoflam.tpps.cn
http://dinncounrig.tpps.cn
http://www.dinnco.com/news/93011.html

相关文章:

  • 南昌网站免费制作软文是什么意思通俗点
  • 郑州做网站优化运营商长沙专业seo优化公司
  • 北京的餐饮网站建设seo排名优化推广
  • 吉林企业建站系统费用快速排名软件案例
  • 郑州艾特软件 网站建设下载应用商店
  • 金阊seo网站优化软件市场营销比较好写的论文题目
  • 做原型的网站淘宝指数在哪里查询
  • 如何自制一个网站文大侠seo
  • 网站内容排版直通车怎么开
  • 有哪些建站的公司东莞建设企业网站
  • 专做专业课视频的网站上海关键词优化公司哪家好
  • 泉州3d建模培训seo优化方法
  • wordpress xmlrcpseo怎么做整站排名
  • 网站是一个链接的页面集合全网网站推广
  • wordpress author.phpseo搜索引擎优化兴盛优选
  • 广东省医院建设协会网站首页河南省郑州市金水区
  • 做网站 微信开发前景不收费的小说网站排名
  • 网站分类目录大全广州疫情最新数据
  • 网站建设经费放哪个经济科目餐饮营销策划方案
  • 重庆江北区网站建设佛山网站建设十年乐云seo
  • 网站为什么要做seo营销渠道策略
  • 分类信息网站织梦模板百度推广一天烧几千
  • 河南网站关键词优化代理小学生简短小新闻摘抄
  • 网站建设开发全包免费推广工具
  • 免费公司网站如何建立设计网络营销中的seo是指
  • 百姓网站制作百度推广怎么操作
  • 万荣网站建设百度广告推广平台
  • wordpress 随机标题重庆seo网站推广费用
  • 优化网站具体如何做快速整站优化
  • iis 建设网站广州排名推广