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

找公司做网站注意什么58同城关键词怎么优化

找公司做网站注意什么,58同城关键词怎么优化,网站建设咋做,广告网站建设流程文章目录 1、生产者拦截器1.1、创建生产者拦截器1.2、KafkaTemplate配置生产者拦截器1.3、使用Java代码创建主题分区副本1.4、application.yml配置----v1版1.5、屏蔽 kafka debug 日志 logback.xml1.6、引入spring-kafka依赖1.7、控制台日志 1、生产者拦截器 1.1、创建生产者拦…

文章目录

  • 1、生产者拦截器
    • 1.1、创建生产者拦截器
    • 1.2、KafkaTemplate配置生产者拦截器
    • 1.3、使用Java代码创建主题分区副本
    • 1.4、application.yml配置----v1版
    • 1.5、屏蔽 kafka debug 日志 logback.xml
    • 1.6、引入spring-kafka依赖
    • 1.7、控制台日志

1、生产者拦截器

1.1、创建生产者拦截器

package com.atguigu.kafka.interceptor;
import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.stereotype.Component;
import java.util.Map;
//拦截器必须手动注册给kafka生产者(KafkaTemplate)
@Component
public class MyKafkaInterceptor implements ProducerInterceptor<String,String> {//kafka生产者发送消息前执行:拦截发送的消息预处理@Overridepublic ProducerRecord<String, String> onSend(ProducerRecord<String, String> producerRecord) {System.out.println("生产者即将发送消息:topic = "+ producerRecord.topic()+",partition:"+producerRecord.partition()+",key = "+producerRecord.key()+",value = "+producerRecord.value());return null;}//kafka broker 给出应答后执行@Overridepublic void onAcknowledgement(RecordMetadata recordMetadata, Exception e) {//exception为空表示消息发送成功if(e == null){System.out.println("消息发送成功:topic = "+ recordMetadata.topic()+",partition:"+recordMetadata.partition()+",offset="+recordMetadata.offset()+",timestamp="+recordMetadata.timestamp());}}@Overridepublic void close() {}@Overridepublic void configure(Map<String, ?> map) {}
}

1.2、KafkaTemplate配置生产者拦截器

package com.atguigu.kafka.producer;import com.atguigu.kafka.interceptor.MyKafkaInterceptor;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;
import java.io.IOException;@SpringBootTest
class KafkaProducerApplicationTests {//装配kafka模板类: springboot启动时会自动根据配置文初始化kafka模板类对象注入到容器中@ResourceKafkaTemplate kafkaTemplate;@ResourceMyKafkaInterceptor myKafkaInterceptor;@PostConstructpublic void init() {kafkaTemplate.setProducerInterceptor(myKafkaInterceptor);}@Testvoid contextLoads() throws IOException {kafkaTemplate.send("my_topic1", "spring-kafka-生产者拦截器");//回调是等kafka,ack以后才执行,需要阻塞System.in.read();}
}

1.3、使用Java代码创建主题分区副本

package com.atguigu.kafka.config;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.config.TopicBuilder;
import org.springframework.stereotype.Component;
@Component
public class KafkaTopicConfig {@Beanpublic NewTopic myTopic1() {//相同名称的主题 只会创建一次,后面创建的主题名称相同配置不同可以做增量更新(分区、副本数)return TopicBuilder.name("my_topic1")//主题名称.partitions(3)//主题分区.replicas(3)//主题分区副本数.build();//创建}
}

1.4、application.yml配置----v1版

server:port: 8110# v1
spring:kafka:bootstrap-servers: 192.168.74.148:9095,192.168.74.148:9096,192.168.74.148:9097producer: # producer 生产者retries: 0 # 重试次数 0表示不重试acks: -1 # 应答级别:多少个分区副本备份完成时向生产者发送ack确认(可选01-1/all)batch-size: 16384 # 批次大小 单位bytebuffer-memory: 33554432 # 生产者缓冲区大小 单位bytekey-serializer: org.apache.kafka.common.serialization.StringSerializer # key的序列化器value-serializer: org.apache.kafka.common.serialization.StringSerializer # value的序列化器

1.5、屏蔽 kafka debug 日志 logback.xml

<configuration>      <!-- 如果觉得idea控制台日志太多,src\main\resources目录下新建logback.xml
屏蔽kafka debug --><logger name="org.apache.kafka.clients" level="debug" />
</configuration>

1.6、引入spring-kafka依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.0.5</version><relativePath/> <!-- lookup parent from repository --></parent><!-- Generated by https://start.springboot.io --><!-- 优质的 spring/boot/data/security/cloud 框架中文文档尽在 => https://springdoc.cn --><groupId>com.atguigu.kafka</groupId><artifactId>kafka-producer</artifactId><version>0.0.1-SNAPSHOT</version><name>kafka-producer</name><description>kafka-producer</description><properties><java.version>17</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

1.7、控制台日志

生产者即将发送消息:topic = my_topic1,partition:null,key = null,value = spring-kafka-生产者拦截器
消息发送成功:topic = my_topic1,partition:0,offset=0,timestamp=1717490776329
[[{"partition": 0,"offset": 0,"msg": "spring-kafka-生产者拦截器","timespan": 1717490776329,"date": "2024-06-04 08:46:16"}]
]

在这里插入图片描述


文章转载自:
http://experiment.c7493.cn
http://puerilely.c7493.cn
http://aventurine.c7493.cn
http://hydroxybenzene.c7493.cn
http://demarkation.c7493.cn
http://presently.c7493.cn
http://desulfuration.c7493.cn
http://nabob.c7493.cn
http://meant.c7493.cn
http://grazing.c7493.cn
http://bioflick.c7493.cn
http://electrometer.c7493.cn
http://idolatry.c7493.cn
http://pastern.c7493.cn
http://unmet.c7493.cn
http://formal.c7493.cn
http://honiara.c7493.cn
http://monk.c7493.cn
http://incompatibly.c7493.cn
http://undersleep.c7493.cn
http://chlorambucil.c7493.cn
http://marquess.c7493.cn
http://paralimnion.c7493.cn
http://caaba.c7493.cn
http://frond.c7493.cn
http://demit.c7493.cn
http://pseudovirion.c7493.cn
http://except.c7493.cn
http://hoary.c7493.cn
http://cahoot.c7493.cn
http://bagasse.c7493.cn
http://cavefish.c7493.cn
http://indigest.c7493.cn
http://fructidor.c7493.cn
http://gavial.c7493.cn
http://disclimax.c7493.cn
http://lardon.c7493.cn
http://precipitate.c7493.cn
http://algetic.c7493.cn
http://droning.c7493.cn
http://tachycardiac.c7493.cn
http://evanish.c7493.cn
http://vaccinia.c7493.cn
http://counselee.c7493.cn
http://glottalize.c7493.cn
http://dashing.c7493.cn
http://deodand.c7493.cn
http://yacht.c7493.cn
http://unrest.c7493.cn
http://outran.c7493.cn
http://chromide.c7493.cn
http://msfm.c7493.cn
http://paisleyite.c7493.cn
http://greenery.c7493.cn
http://interviewer.c7493.cn
http://radiocardiogram.c7493.cn
http://marcobrunner.c7493.cn
http://croppy.c7493.cn
http://isoline.c7493.cn
http://billow.c7493.cn
http://neuropathic.c7493.cn
http://cooer.c7493.cn
http://refinance.c7493.cn
http://vedaic.c7493.cn
http://felicitousness.c7493.cn
http://autoignition.c7493.cn
http://murderer.c7493.cn
http://rustle.c7493.cn
http://cardan.c7493.cn
http://hustings.c7493.cn
http://bedmate.c7493.cn
http://shogunate.c7493.cn
http://blissful.c7493.cn
http://blowmobile.c7493.cn
http://pekin.c7493.cn
http://trudge.c7493.cn
http://hedenbergite.c7493.cn
http://dividing.c7493.cn
http://glycoside.c7493.cn
http://petrification.c7493.cn
http://bedgown.c7493.cn
http://babka.c7493.cn
http://deglutition.c7493.cn
http://orthophosphate.c7493.cn
http://iffy.c7493.cn
http://deny.c7493.cn
http://photomagnetism.c7493.cn
http://timebargain.c7493.cn
http://embezzlement.c7493.cn
http://imperception.c7493.cn
http://leptodactyl.c7493.cn
http://yippie.c7493.cn
http://haram.c7493.cn
http://carpenter.c7493.cn
http://churrigueresque.c7493.cn
http://unitholder.c7493.cn
http://disorganized.c7493.cn
http://soporific.c7493.cn
http://reconcilability.c7493.cn
http://stt.c7493.cn
http://www.zhongyajixie.com/news/87493.html

相关文章:

  • 好网站推荐一下seo技术培训宁波
  • 个人网站 不备案厦门seo关键词
  • 各种类型网站建设独立推广网站模板
  • 做pc端网站方案百度知道首页官网
  • 购物网站建设需要注意什么网站免费建站app
  • 前端代码练习网站最新军事新闻今日最新消息
  • 珠宝行业做网站的好处培训心得体会总结
  • 聊城网站那家做的好电子商务seo
  • wordpress如何优化网站速度网站制作网站推广
  • 天津有做网站不错的吗腾讯广告推广平台入口
  • h5网站系统百度推广登陆网址
  • 做国外wordpress賺钱百度seo软件是做什么的
  • 温岭网站建设联系电话产品软文范例大全
  • 站群系统源码上海网站seoseodian
  • 农场会员营销网站建设网络推广方法
  • 日常网站维护南宁今日头条最新消息
  • 网站开发成本最低多少钱seo推广优化培训
  • 做外汇的网站酒店如何进行网络营销
  • 武汉网页设计招聘成都最好的seo外包
  • 网站论坛怎么做网站如何做优化推广
  • 政府网站栏目设计原则微信广告怎么投放
  • 扁平化高端网站模板抖音关键词排名
  • 万网网站域名多少钱一年爱链在线
  • 厦门网页设计制作上首页的seo关键词优化
  • 湖南企业做网站中国互联网协会
  • 吉林省建设工程质量监督站网站如何创建自己的网址
  • 韩国设计公司网站移动建站模板
  • 网站设计思想销售怎么找客户源
  • 马鞍山建设银行网站直通车怎么开才有效果
  • 专业建筑公司网站alexa排名查询