zoukankan      html  css  js  c++  java
  • eureka 消费服务

    1:pom

        <!---  eureka-client  -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>

    2:yml

    eureka:
      client:
        fetch-registry: true
        register-with-eureka: true
        service-url:
          defaultZone: http://localhost:7001/eureka

    3:注解

    @EnableEurekaClient
    @SpringBootApplication
    public class OrderMain80 {
    
        public static void main(String[] args) {
            SpringApplication.run(OrderMain80.class);
        }
    }

    端口分配 80

    4使用eureka服务中的名称调用

      服务的名称:

    spring:
      application:
        name: cloud-payment-service  

        8001,8002端口

      客户端调用

        @Autowired
        private RestTemplate restTemplate;
    
        private String url = "http://CLOUD-PAYMENT-SERVICE";  //写到配置文件中
    
        @RequestMapping("/insert")
        public BaseResult insert(Payment payment) {
    
            restTemplate.postForEntity("url" + "/payment/insert", payment, BaseResult.class);
    
            return sendSuccess();
        }

      备注:注册bean,开启负载

    @Component
    @Configuration
    public class AppConfiguration {
        
        @LoadBalanced   // 负载均衡
        @Bean
        public RestTemplate restTemplate() {
            return new RestTemplate();
        }
    }

      

  • 相关阅读:
    忘记IBM服务器的登录IP
    分层思想
    防火墙的发展历史
    存储相关
    HCIE_交换篇_ARP欺骗
    堡垒机与网闸
    防止ARP欺骗
    信息安全等级保护
    DPM如何创建存储池?
    Lync2013的会话
  • 原文地址:https://www.cnblogs.com/draymond/p/12708854.html
Copyright © 2011-2022 走看看