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

如何新建网站dw弄个小程序要多少钱

如何新建网站dw,弄个小程序要多少钱,网站提示代码,兴县做网站的公司问题分析 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://www.yayakq.cn/news/163609/

相关文章:

  • 免费建一级域名网站qq推广赚钱一个2元
  • NET开发网站开发工程师招聘东营招聘网
  • 重庆哪家在做网站建设公益网站建设的意义
  • 网站怎么进入后台管理临高网站建设
  • 网站备案查询主办单位性质为个人常州住房和城乡建设局网站首页
  • 世纪购网站开发招聘wordpress新页面代码
  • 网站前台做哪些工作内容网线制作实训总结
  • 张家港网站建设门店江津网站建设方案
  • 建设网站需要哪些元素建立微信群的步骤
  • 原江苏省建设厅网站搜索引擎营销案例分析题
  • 网站建设模板套用免费网络课程平台
  • 网站建设科技公司外部环境分析seo职业技能培训班
  • 网站首页布局设计教程深圳建站模板购买
  • 学做标书的网站德州市建设街小学网站
  • 企业网站建设企业番禺建设网站报价
  • 为企业设计一个网站凤凰一级a做爰片免费网站
  • 网站维护合同深圳哪里有可以做网站跳转的公司
  • 网站制作青岛工程建设采购有哪些网站
  • 什么类型的网站比较容易做公司想做个自己的网站怎么做的
  • 彩票资讯网站建设公司建网站制作平台
  • wordpress好的博客主题手机优化师下载
  • 网站被做跳转企业展厅设计公司案例欣赏
  • 南同网站建设高端网站建设公司新鸿儒
  • 如何做链接淘宝客的网站合肥室内设计培训学校哪家好
  • 正规的网站制作哪个好ui界面设计培训班
  • 建设公司网站需要准备哪些材料广州代运营公司有哪些
  • 网站没收录了怎么办自己网上开店的步骤
  • 建网站得多少钱用dw制作网页步骤
  • 高端网站建设加盟专业的推广公司
  • 北京学设计去哪个网站好中小企业网站建设应该注意什么