1、建Module
2、改POM
!-- SpringBoot整合zookeeper客户端 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId> <!--先排除自带的zookeeper--> <exclusions> <exclusion> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> </exclusion> </exclusions> </dependency>
3、写YML
#注册到zookeeper地址 zookeeper: connect-string: 192.168.111.144:2181(自己的zookeeper所在的ip:zookeeper的端口号)
)
4、主启动
5、业务层
1、配置Bean
@Configuration public class ApplicationContextBean { @Bean @LoadBalanced public RestTemplate getRestTemplate() { return new RestTemplate(); } }
2、Controller
@RestController public class OrderZKController { public static final String INVOKE_URL = "http://cloud-provider-payment"; @Autowired private RestTemplate restTemplate; @RequestMapping(value = "/consumer/payment/zk") public String paymentInfo() { String result = restTemplate.getForObject(INVOKE_URL+"/payment/zk", String.class); System.out.println("消费者调用支付服务(zookeeper)--->result:" + result); return result; } }
标签:zookeeper,服务,String,Zookeeper,RestTemplate,result,public,cloud,消费者 From: https://www.cnblogs.com/ai377377/p/16913129.html