zoukankan      html  css  js  c++  java
  • eureka2

    搭建eureka注册中心

    eureka服务配置文件

    server:
      port: 10086  #服务端口
    spring:
      application:
        name: register-eureka #服务名
    eureka:
      client:
        service-url:
          defaultZone: http://localhost:10086/eureka/ #注册中心地址
    
    

    eureka启动类配置

    @SpringBootApplication
    @EnableEurekaServer //标记eureka注册中心
    public class RegisterEurekaApplication {
        public static void main(String[] args) {
            SpringApplication.run(RegisterEurekaApplication.class, args);
        }
    
    }
    
    

    服务提供者 serve-eureka

    serve-eureka配置

    server.port=8080
    spring.application.name=serve-eureka 
    eureka.client.service-url.defaultZone= http://localhost:10086/eureka/  ##连接注册中心
    
    

    serve-eureka启动类

    @SpringBootApplication
    @EnableDiscoveryClient //标记时eureka服务
    public class ServeEurekaApplication {
        public static void main(String[] args) {
            SpringApplication.run(ServeEurekaApplication.class, args);
        }
    
    }
    

    服务消费者consume-eureka

    consume-eureka配置

    server.port=80
    spring.application.name=consume-eureka
    eureka.client.service-url.defaultZone= http://localhost:10086/eureka/
    

    consume-eureka启动类

    @SpringBootApplication
    @EnableCircuitBreaker//开启Hystyix熔断
    public class ConsumeEurekaApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ConsumeEurekaApplication.class, args);
        }
        @Bean
        @LoadBalanced //开启ribbon负载均衡
        public RestTemplate restTemplate(){
            return new RestTemplate();
        }
    }
    
    

    consume-eureka 服务入口

    @RestController
    @DefaultProperties(defaultFallback = "fallback") //全局熔断
    public class LoginController {
        @Autowired
        private RestTemplate restTemplate;
        
        @GetMapping("login")
        @HystrixCommand
        public String login(@RequestParam String message){
            System.out.println("restTemplate请求服务时直接使用服务名进行请求 可以实现负载均衡");
            return restTemplate.getForObject("http://serve-eureka/index/"+message,String.class);
        }
    
        //全局熔断方法
        public String fallback(){
            return "请求超时";
        }
    }
    
    
    代码使世界更精彩
  • 相关阅读:
    The required MAP capability is more than the supported max container capability in the cluster. Killing the Job. mapResourceRequest: <memory:2048, vCores:2> maxContainerCapability:<memory:1024, vCores
    centos6.8安装cdh6.0.0
    oracle拼接sql
    数据插入不覆盖更新,设置定时任务
    支持向量机在 R 语言中的实现和使用
    怎么彻底去掉office365
    汽车电子软件规范学习
    ISO/IEC TS 17961 C Secure Coding Rules
    UML图
    Gitflow工作流程
  • 原文地址:https://www.cnblogs.com/lgx123/p/14862253.html
Copyright © 2011-2022 走看看