栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

zookeepe服务注册与发现

zookeepe服务注册与发现

zookeeper学习 学习步骤: 1.zookeeper服务启动 2.建module 3.改pom, 加入zookeeper相关依赖
		
            org.springframework.cloud
            spring-cloud-starter-zookeeper-discovery
            3.1.1
        
4.写yml配置文件
#该服务的端口号
server:
  port: 8004
spring:
  application:
    name: cloud-payment-server  # 该服务的名称
  cloud:
    zookeeper:
      discovery:
        enabled: true			# 开启服务
      connect-string: 192.123.32.19:2181	#服务注册中心(zookeeper)地址
      connection-timeout: 1000000	# 连接超时时间
5.主启动
@SpringBootApplication
@EnableDiscoveryClient
public class ProviderPaymentMain8004 {
    public static void main(String[] args) {
        SpringApplication.run(ProviderPaymentMain8004.class, args);
    }
}
6.写业务
@RestController
@Slf4j
public class PaymentController8004 {

    @Value("${server.port}")
    private String serverPort;

    @GetMapping(value = "/payment/pro")
    public String payment(){
        return "payment serverPort ==>" + serverPort + UUID.randomUUID().toString();
    }
}
// 配置类
//使用RestTemplate 远程调用(底层使用的还是HttpClient)

@Configuration
public class BeanConf {

    @Bean
    // 开启负载均衡
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }
}
// 控制器

@RestController
@Slf4j
public class ConsumerZkOrder80Controller {

    @Autowired
    private RestTemplate restTemplate;

    // 远程服务地址(服务提供方)
    private static final String INVOKE_URL = "http://cloud-payment-server";

    @GetMapping("/remote/server")
    public String remoteService(){
        return restTemplate.getForObject(INVOKE_URL + "/payment/pro",String.class);
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/762297.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号