Nacos搭建

  • 创建文件conf/cluster.conf 配置地址

    ip1:port1
    ip2:port2
    # nacos对应的ip与端口,每个ncaos都要有本文件
  • 然后修改application.properties对应端口
  • 数据库使用同一个数据库或者

    • 使用主备模式
    • 者高可用集群
  • start.sh 分别启动

服务注册与调用

  • RestTemplete:SpringCloud alibaba 封装了 它ribbon,使之有负载均衡功能

    • // 客户端的负载均衡
      @LoadBalanced  // 从nacos获取服务列表,自己确定请求位置
      @Bean
      public RestTemplate restTemplate(){}
      
      @Bean// 自定义负载均衡策略 ,NacosRule nacos提供的,可在nacos设置每个服务的权重
    
    - getForObject
    
    - getForEntity
    
    - postForObject
    
    - MultiValueMap
  • Feign

    • 声明式rest客户端
    • ribbon与feign整合,
    • 简化消费者使用
    • spring-cloud-starter-openfeign
      // 绑定远程服务
      @Feign(name="remote-service-name")
      public interface EchoService(){
          @GetMapping("/xxx")
          default String hello();

Sentinal

  • customer,provider引入jar即可
  • 配置sentinal地址,sentinal web端会访问

Spring Cloud Getway

  • 有sentinal 的功能
  • 路由

注:

request.getRequestDispatcher("xxx").forward(request,response);
reponse.sendRedirect("http://yyy")

标签: none

评论已关闭