新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
zookeeper(4)注冊中心
案例
注冊中心可以使用Eureka來實現(xiàn),這個比較簡單,可以看之前的例子spring-cloud。
為龍港等地區(qū)用戶提供了全套網(wǎng)頁設計制作服務,及龍港網(wǎng)站建設行業(yè)解決方案。主營業(yè)務為網(wǎng)站建設、成都做網(wǎng)站、龍港網(wǎng)站設計,以傳統(tǒng)方式定制建設網(wǎng)站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
那么使用zookeeper如何來實現(xiàn)注冊中心呢?
基于spring cloud我們也可以非常簡單的實現(xiàn)。
1、利用之前搭建的zookeeper集群,zookeeper集群
2、新建maven工程
1、POM文件如下:
org.springframework.boot
spring-boot-starter-parent
2.1.4.RELEASE
4.0.0
com.jane
zookeeper-register-server
1.0-SNAPSHOT
1.8
Greenwich.SR1
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-zookeeper-discovery
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
2、啟動文件如下:
package com.jane.zk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableCaching
@EnableDiscoveryClient
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}
3、配置文件如下:
spring.application.name=order-service
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
server.port=0
spring.cloud.zookeeper.connect-string=www.****.com:2181,www.*****.club:2181,www.*****.club:2181
啟動之后,查看zookeeper的節(jié)點
1、服務節(jié)點都位于目錄services下:
2、services目錄下有對應的服務節(jié)點
3、查看服務節(jié)點對應的節(jié)點信息
至此,一個服務就成功注冊到了zookeeper上了。
新聞標題:zookeeper(4)注冊中心
網(wǎng)站URL:http://www.ef60e0e.cn/article/gshepc.html