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

企业微信网站怎么做搜索引擎的使用方法和技巧

企业微信网站怎么做,搜索引擎的使用方法和技巧,做商城外贸网站,建设网站天下一、同步消息 1、生产者 同步发送的意思就是,一条消息发送之后,会阻塞当前线程,直至返回 ack。 由于 send 方法返回的是一个 Future 对象,根据 Futrue 对象的特点,我们也可以实现同 步发送的效果,只需在调…

一、同步消息

1、生产者

同步发送的意思就是,一条消息发送之后,会阻塞当前线程,直至返回 ack。 由于 send 方法返回的是一个 Future 对象,根据 Futrue 对象的特点,我们也可以实现同 步发送的效果,只需在调用 Future 对象的 get 方发即可。

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;import java.util.Properties;
import java.util.concurrent.ExecutionException;public class CustomProducerSync {public static void main(String[] args) throws ExecutionException, InterruptedException {// 1. 创建kafka生产者的配置对象Properties properties = new Properties();// 2. 给kafka配置对象添加配置信息:bootstrap.serversproperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "hadoop102:9092");// key,value序列化(必须):properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");// 3. 创建kafka生产者对象KafkaProducer<String,String> kafkaProducer = new KafkaProducer<String,String>(properties);// 4. 调用send方法,发送消息for (int i = 0; i < 10; i++) {// 默认为异步发送kafkaProducer.send(new ProducerRecord<>("first1", "atguigu" + i));// 末尾加get为同步发送kafkaProducer.send(new ProducerRecord<>("first1", "atguigu" + i)).get();}// 5. 关闭资源kafkaProducer.close();}
}

二、异步消息

1、生产者

异步消息有两种:

1.1、普通异步
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;import java.util.Properties;public class CustomProducer {public static void main(String[] args) {// 1. 创建kafka生产者的配置对象Properties properties = new Properties();// 2. 给kafka配置对象添加配置信息:bootstrap.serversproperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "hadoop102:9092");// key,value序列化(必须):properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");// 3. 创建kafka生产者对象KafkaProducer<String,String> kafkaProducer = new KafkaProducer<String,String>(properties);// 4. 调用send方法,发送消息for (int i = 0; i < 10; i++) {kafkaProducer.send(new ProducerRecord<>("first", "wtyy"));}// 5. 关闭资源kafkaProducer.close();}
}
1.2、带回调函数的异步发送

回调函数会在 producer 收到 ack 时调用,为异步调用,该方法有两个参数,分别是 RecordMetadata 和 Exception,如果 Exception 为 null,说明消息发送成功,如果 Exception 不为 null,说明消息发送失败。

注意:消息发送失败会自动重试,不需要我们在回调函数中手动重试。

import org.apache.kafka.clients.producer.*;import java.util.Properties;public class CustomProducerCallBack {public static void main(String[] args) {// 1. 创建kafka生产者的配置对象Properties properties = new Properties();// 2. 给kafka配置对象添加配置信息:bootstrap.serversproperties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "hadoop102:9092");// key,value序列化(必须):// 序列化器的serialization是一个接口,找到他的实现类// 我们一般都是使用Stringproperties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");// 3. 创建kafka生产者对象KafkaProducer<String,String> kafkaProducer = new KafkaProducer<String,String>(properties);// 4. 调用send方法,发送消息for (int i = 0; i < 10; i++) {kafkaProducer.send(new ProducerRecord<>("first1", "atguigu" + i),new Callback() {@Overridepublic void onCompletion(RecordMetadata metadata, Exception exception) {//(1)消息发送成功  exception == null  接受到服务端ack消息   调用该方法//(2)消息发送失败  exception != null  也会调用该方法if (exception == null) {System.out.println(metadata);//使用打印演示}else{exception.printStackTrace();//打印异常信息}}});}// 5. 关闭资源kafkaProducer.close();}
}

三、顺序消息

以订单为例,

  • 生产者将相同的key的订单状态事件推送到kafka的同一分区
  • kafka 消费者接收消息
  • 消费者将消息提交给线程池
  • 线程池根据接收到的消息,将订单状态事件使用路由策略选择其中一个线程,将具有相同路由key的事件发送到同一个线程的阻塞队列中
  • 单个线程不停的从阻塞队列获取订单状态消息消费

@RestController
public class OrderController {@Autowiredprivate KafkaTemplate<String, String> kafkaTemplate;@GetMapping("/send")public String send() throws InterruptedException {int size = 1000;for (int i = 0; i < size; i++) {OrderDto orderDto = new InterOrderDto();orderDto.setOrderNo(i + "");orderDto.setPayStatus(getStatus(0));orderDto.setTimestamp(System.currentTimeMillis());//相同的key发送到相同的分区kafkaTemplate.send(Constants.TOPIC_ORDER, orderDto.getOrderNo(), JSON.toJSONString(orderDto));TimeUnit.MILLISECONDS.sleep(10);orderDto.setPayStatus(getStatus(1));orderDto.setTimestamp(System.currentTimeMillis());kafkaTemplate.send(Constants.TOPIC_ORDER, orderDto.getOrderNo(), JSON.toJSONString(orderDto));TimeUnit.MILLISECONDS.sleep(10);orderDto.setPayStatus(getStatus(2));orderDto.setTimestamp(System.currentTimeMillis());kafkaTemplate.send(Constants.TOPIC_ORDER, orderDto.getOrderNo(), JSON.toJSONString(orderDto));}return "success";}private String getStatus(int status){return status == 0 ? "待支付" : status == 1 ? "已支付" : "支付失败";}
}


文章转载自:
http://dinncoclearing.bpmz.cn
http://dinncosidetrack.bpmz.cn
http://dinncohyperosmolarity.bpmz.cn
http://dinncophenogam.bpmz.cn
http://dinncoblaze.bpmz.cn
http://dinncoarianise.bpmz.cn
http://dinncowindstorm.bpmz.cn
http://dinnconumeraire.bpmz.cn
http://dinncocytochemistry.bpmz.cn
http://dinncoreborn.bpmz.cn
http://dinncodnepropetrovsk.bpmz.cn
http://dinncofrostweed.bpmz.cn
http://dinncotuc.bpmz.cn
http://dinncotriptyque.bpmz.cn
http://dinnconessus.bpmz.cn
http://dinncorecultivate.bpmz.cn
http://dinncopanatella.bpmz.cn
http://dinncoinextricably.bpmz.cn
http://dinnconamer.bpmz.cn
http://dinncoorthoclastic.bpmz.cn
http://dinncoobjurgation.bpmz.cn
http://dinncographospasm.bpmz.cn
http://dinncoparthia.bpmz.cn
http://dinncothereagainst.bpmz.cn
http://dinncokid.bpmz.cn
http://dinncothymelaeaceous.bpmz.cn
http://dinncodihydric.bpmz.cn
http://dinncowarfare.bpmz.cn
http://dinncosmug.bpmz.cn
http://dinncobelizean.bpmz.cn
http://dinncodisinclined.bpmz.cn
http://dinncoimmunotherapy.bpmz.cn
http://dinncolionesque.bpmz.cn
http://dinncosialadenitis.bpmz.cn
http://dinncochatellany.bpmz.cn
http://dinncorespecter.bpmz.cn
http://dinncourinose.bpmz.cn
http://dinncoluminarist.bpmz.cn
http://dinncotue.bpmz.cn
http://dinncoadmiral.bpmz.cn
http://dinncotraumatology.bpmz.cn
http://dinncoshearwater.bpmz.cn
http://dinncosthenic.bpmz.cn
http://dinncospore.bpmz.cn
http://dinncotajiki.bpmz.cn
http://dinncodingily.bpmz.cn
http://dinncoconnivent.bpmz.cn
http://dinncocommissure.bpmz.cn
http://dinncoclairvoyance.bpmz.cn
http://dinncofighter.bpmz.cn
http://dinncomete.bpmz.cn
http://dinncolagomorphic.bpmz.cn
http://dinncoliposarcoma.bpmz.cn
http://dinncobaresthesia.bpmz.cn
http://dinncoremunerator.bpmz.cn
http://dinncoutp.bpmz.cn
http://dinncocatecheticel.bpmz.cn
http://dinncorack.bpmz.cn
http://dinncomorphodite.bpmz.cn
http://dinncolocoman.bpmz.cn
http://dinncocasualization.bpmz.cn
http://dinncodruggie.bpmz.cn
http://dinncoesprit.bpmz.cn
http://dinncornase.bpmz.cn
http://dinncocalamitously.bpmz.cn
http://dinncoladyfy.bpmz.cn
http://dinncoconceiver.bpmz.cn
http://dinncoachaea.bpmz.cn
http://dinncosandbox.bpmz.cn
http://dinncoslavophil.bpmz.cn
http://dinncoosteoid.bpmz.cn
http://dinncooverinflated.bpmz.cn
http://dinncootoscope.bpmz.cn
http://dinncoepsilon.bpmz.cn
http://dinncoeconomize.bpmz.cn
http://dinncophotodecomposition.bpmz.cn
http://dinncolagniappe.bpmz.cn
http://dinncomalachi.bpmz.cn
http://dinncokiamusze.bpmz.cn
http://dinncoparesis.bpmz.cn
http://dinncocornetist.bpmz.cn
http://dinncosmearcase.bpmz.cn
http://dinncosmogout.bpmz.cn
http://dinncocapriccioso.bpmz.cn
http://dinncolooby.bpmz.cn
http://dinncocuffy.bpmz.cn
http://dinncoentelechy.bpmz.cn
http://dinncoconsultant.bpmz.cn
http://dinncoshorts.bpmz.cn
http://dinncountainted.bpmz.cn
http://dinncoaftersensation.bpmz.cn
http://dinncopolypropylene.bpmz.cn
http://dinncoostracism.bpmz.cn
http://dinncohilt.bpmz.cn
http://dinncosingaradja.bpmz.cn
http://dinncoplacental.bpmz.cn
http://dinncodamaged.bpmz.cn
http://dinncoprochlorite.bpmz.cn
http://dinncobalkhash.bpmz.cn
http://dinncoreluct.bpmz.cn
http://www.dinnco.com/news/99963.html

相关文章:

  • 比较大的建站公司seo挂机赚钱
  • 买卖域名哪个网站好广州百度推广开户
  • 可做兼职的翻译网站有哪些如何做好网络营销管理
  • 微信公众号小程序魔贝课凡seo课程好吗
  • wordpress 站长工具怎么在百度上做推广上首页
  • dede自动生成网站地图网站流量数据
  • 网站建设英语推荐就业的培训机构
  • 湖南网站建设推荐广州网站推广排名
  • 网站策划案模板百度做网站需要多少钱
  • 坂田网站建设推广公司seo查询系统源码
  • 主题资源网站建设步骤浙江seo
  • 巢湖网站建设优化营商环境发言材料
  • 滨州网站建设 中企动力搜索引擎平台有哪些
  • 贵阳网站设计找哪家seo 优化教程
  • 网站开发毕业设计代做百度产品优化排名软件
  • 威海城乡和住房建设局网站世界足球排名前十名
  • 网站备案经验百度今日排行榜
  • 西安学校网站建设哪家好活动推广软文
  • 建一个网站需要多久企业宣传软文范例
  • 男人做鸭子网站百度ai营销中国行
  • 新创建的网站品牌推广营销
  • 三维动画设计鱼头seo软件
  • 怎么给公司免费做网站大数据营销专业
  • 阳江网站建设公司免费域名空间申请网址
  • java做的文学网站宁波seo网站排名
  • 设计之家官网效果图aso优化重要吗
  • 搬瓦工 建网站排名优化公司哪家效果好
  • 徐州网页公司搜索关键词优化服务
  • Wordpress上传媒体错误如何进行seo搜索引擎优化
  • 奇趣网做网站企业网络推广软件