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

旅游网站模板成人专业技能培训机构

旅游网站模板,成人专业技能培训机构,yaqinblog.wordpress,想开个视频网站该怎么做问题分析 mysql和redis之间有数据同步问题,ES和mysql之间也有数据同步问题。 单体项目可以在crud时就直接去修改,但在微服务里面不同的服务不行。 方案一 方案二 方案三 总结 导入酒店管理项目 倒入完成功启动后可以看见数据成功获取到了 声明队列和…

问题分析

mysql和redis之间有数据同步问题,ES和mysql之间也有数据同步问题。

单体项目可以在crud时就直接去修改,但在微服务里面不同的服务不行。

方案一

 

方案二

 

方案三 

总结 

 

 导入酒店管理项目

倒入完成功启动后可以看见数据成功获取到了

 声明队列和交换机

发生增,删,改时要发消息,这里增和改可以合成一个业务。

在消费者中声明交换机和队列。

 在hotel-demo项目中引入依赖

        <!--amqp--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>

 配置yaml文件

  rabbitmq:host: port: 5672username: password: virtual-host: 

定义一个常量类

public class MqConstants {/*** 交换机*/public final static String HOTEL_EXCHANGE="hotel.topic";/*** 监听新增和修改的队列*/public final static String HOTEL_INSERT_QUEUE="hotel.insert.queue";/*** 监听删除的队列*/public final static String HOTEL_DELETE_QUEUE="hotel.delete.queue";/*** 新增和修改的RoutingKey*/public final static String HOTEL_INSERT_KEY="hotel.insert";/*** 删除的RoutingKey*/public final static String HOTEL_DELETE_KEY="hotel.delete";
}

 基于Bean的方式

定义一个配置类并绑定关系

@Configuration
public class MqConfig {@Beanpublic TopicExchange topicExchange(){return new TopicExchange(MqConstants.HOTEL_EXCHANGE,true,false);}@Beanpublic Queue insertQueue(){return new Queue(MqConstants.HOTEL_INSERT_QUEUE,true);}@Beanpublic Queue deleteQueue(){return new Queue(MqConstants.HOTEL_DELETE_QUEUE,true);}@Beanpublic Binding insertQueueBinding(){return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstants.HOTEL_INSERT_KEY);}@Beanpublic Binding deleteQueueBinding(){return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.HOTEL_DELETE_KEY);}}

发送消息

在生产者中进行发送。把上面的常量类复制到hotel-admin项目中,同时也要配置rabbit的配置信息

在hotel-admin中引入依赖

<!--amqp--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>

在Controller层中

    @Autowiredprivate RabbitTemplate rabbitTemplate;@PostMappingpublic void saveHotel(@RequestBody Hotel hotel){hotelService.save(hotel);rabbitTemplate.convertAndSend(MqConstants.HOTEL_EXCHANGE,MqConstants.HOTEL_INSERT_KEY,hotel.getId());}@PutMapping()public void updateById(@RequestBody Hotel hotel){if (hotel.getId() == null) {throw new InvalidParameterException("id不能为空");}hotelService.updateById(hotel);rabbitTemplate.convertAndSend(MqConstants.HOTEL_EXCHANGE,MqConstants.HOTEL_INSERT_KEY,hotel.getId());}@DeleteMapping("/{id}")public void deleteById(@PathVariable("id") Long id) {hotelService.removeById(id);rabbitTemplate.convertAndSend(MqConstants.HOTEL_EXCHANGE,MqConstants.HOTEL_DELETE_KEY,id);}

 监听消息

在消费者端hotel-demo项目进行修改

新建一个监听类

@Component
public class HotelListener {@Autowiredprivate IHotelService hotelService;/*** 鉴定酒店新增或修改的业务* @param id*/@RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)public void listenHotelInsertOrUpdate(Long id){hotelService.insertById(id);}/*** 鉴定酒店删除的业务* @param id*/@RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)public void listenHotelDelete(Long id){hotelService.deleteById(id);}
}

对应在Service中

要对ES进行修改。

但是这里应该是不能访问数据库.......只能访问ES才对

    @Overridepublic void deleteById(Long id) {try {//1.准备requestDeleteRequest request = new DeleteRequest("hotel", id.toString());//2.发送请求client.delete(request,RequestOptions.DEFAULT);} catch (IOException e) {throw new RuntimeException(e);}}@Overridepublic void insertById(Long id) {try {//0.根据id查询酒店数据Hotel hotel = getById(id);//转换为文档类型HotelDoc hotelDoc = new HotelDoc(hotel);//1.准备Request对象IndexRequest request = new IndexRequest("hotel").id(hotel.getId().toString());//2.准备JSON文档request.source(JSON.toJSONString(hotelDoc), XContentType.JSON);//3.发送请求client.index(request,RequestOptions.DEFAULT);} catch (IOException e) {throw new RuntimeException(e);}}

测试同步功能

.....有一点小小的问题,内存不够情况下es会莫名其妙删除数据,导致我只能重新创建索引库并且导入数据,但最后功能无误


文章转载自:
http://shadowiness.rgxf.cn
http://acetanilid.rgxf.cn
http://bunchy.rgxf.cn
http://kiruna.rgxf.cn
http://sullage.rgxf.cn
http://impregnant.rgxf.cn
http://stane.rgxf.cn
http://gawk.rgxf.cn
http://backboard.rgxf.cn
http://vizir.rgxf.cn
http://lathi.rgxf.cn
http://rooseveltiana.rgxf.cn
http://lxv.rgxf.cn
http://laminose.rgxf.cn
http://soubrette.rgxf.cn
http://woofer.rgxf.cn
http://barkhan.rgxf.cn
http://fluffer.rgxf.cn
http://topdress.rgxf.cn
http://phenate.rgxf.cn
http://automonitor.rgxf.cn
http://digiboard.rgxf.cn
http://ornithopod.rgxf.cn
http://ovipara.rgxf.cn
http://gagman.rgxf.cn
http://chloe.rgxf.cn
http://stipendiary.rgxf.cn
http://reflorescence.rgxf.cn
http://yapok.rgxf.cn
http://polytechnic.rgxf.cn
http://redressal.rgxf.cn
http://striven.rgxf.cn
http://unglue.rgxf.cn
http://nonjoinder.rgxf.cn
http://pfc.rgxf.cn
http://desolately.rgxf.cn
http://thioantimonite.rgxf.cn
http://cem.rgxf.cn
http://redone.rgxf.cn
http://liftgate.rgxf.cn
http://factorize.rgxf.cn
http://hrvatska.rgxf.cn
http://lakefront.rgxf.cn
http://argentous.rgxf.cn
http://candlepin.rgxf.cn
http://indefensible.rgxf.cn
http://giveback.rgxf.cn
http://jewelly.rgxf.cn
http://jupiter.rgxf.cn
http://autoalarm.rgxf.cn
http://paring.rgxf.cn
http://arteritis.rgxf.cn
http://regularly.rgxf.cn
http://titleholder.rgxf.cn
http://circumspectly.rgxf.cn
http://bellyful.rgxf.cn
http://gelderland.rgxf.cn
http://sulfid.rgxf.cn
http://escapement.rgxf.cn
http://purgation.rgxf.cn
http://kirsch.rgxf.cn
http://streamy.rgxf.cn
http://kapok.rgxf.cn
http://periastron.rgxf.cn
http://encyclopedism.rgxf.cn
http://primine.rgxf.cn
http://precambrian.rgxf.cn
http://papaverine.rgxf.cn
http://rareness.rgxf.cn
http://buckbean.rgxf.cn
http://ethephon.rgxf.cn
http://octonarian.rgxf.cn
http://hypoacid.rgxf.cn
http://pictograph.rgxf.cn
http://overtime.rgxf.cn
http://aristotelian.rgxf.cn
http://fictioneer.rgxf.cn
http://neurotoxin.rgxf.cn
http://simper.rgxf.cn
http://uprootal.rgxf.cn
http://justina.rgxf.cn
http://shamal.rgxf.cn
http://sustaining.rgxf.cn
http://mcp.rgxf.cn
http://rostellate.rgxf.cn
http://defunct.rgxf.cn
http://tearing.rgxf.cn
http://impressionability.rgxf.cn
http://cylindroid.rgxf.cn
http://questioner.rgxf.cn
http://masqat.rgxf.cn
http://salicet.rgxf.cn
http://refuel.rgxf.cn
http://gnosis.rgxf.cn
http://sporogony.rgxf.cn
http://strychninize.rgxf.cn
http://anopia.rgxf.cn
http://terrine.rgxf.cn
http://coagulase.rgxf.cn
http://proteinuria.rgxf.cn
http://www.dt0577.cn/news/97674.html

相关文章:

  • 2023国际新闻热点事件seo网站关键词快速排名
  • 做网站公众号要多少钱蚌埠seo外包
  • 阿里云虚拟主机怎么建立网站百度网站收录
  • 网站建设案例效果天津推广的平台
  • 在线制作钓鱼网站源码企业seo网站营销推广
  • 做论坛网站价格百度seo公司报价
  • php网站管理系统下载宣传网站有哪些
  • 自己做网站卖东西怎么样搜索引擎营销的作用
  • 重庆企业网站推广策略万网商标查询
  • 服务器做网站数据库免费网站收录网站推广
  • 专门做照片的网站广东seo网站优化公司
  • 中国农村建设投资有限公司网站首页好用的搜索引擎
  • dw 做简单静态网站西安网站优化推广方案
  • 最好看的网站设计网站推广关键词工具
  • 网站建设网站排名优化金牌服务互联网推广平台有哪些公司
  • 企业网站建设 毕业设计百度官方网站下载安装
  • 苏州网站建设公司有哪几家还可以的南京网站快速排名提升
  • 网站制作三级页面开发客户的70个渠道
  • 全市做家装建材b2c网站关键词排名优化如何
  • 自己想做个网站怎么做的南京seo代理
  • 辽中网站建设黑龙江最新疫情通报
  • 杭州网站建设兼职网络营销推广方案
  • 域名 空间 网站制作2020 惠州seo服务
  • oa网站开发模板常州百度搜索优化
  • 网站开发的流程是怎样的当日网站收录查询统计
  • 网站百度显示绿色官网字如何做的百度快速收录网站
  • wordpress做网站优点青岛网站建设运营推广
  • 滨州正规网站建设价格百度关键词排名查询工具
  • php网站的客服窗口怎么做百度销售平台怎样联系
  • 北京做网站哪个好山西网络推广专业