zookeeper(4)注册中心-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

zookeeper(4)注册中心

案例

注册中心可以使用Eureka来实现,这个比较简单,可以看之前的例子spring-cloud。

为龙港等地区用户提供了全套网页设计制作服务,及龙港网站建设行业解决方案。主营业务为网站建设、成都做网站、龙港网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

那么使用zookeeper如何来实现注册中心呢?

基于spring cloud我们也可以非常简单的实现。

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的节点

1、服务节点都位于目录services下:
zookeeper(4)注册中心

2、services目录下有对应的服务节点
zookeeper(4)注册中心

3、查看服务节点对应的节点信息
zookeeper(4)注册中心

至此,一个服务就成功注册到了zookeeper上了。


网页题目:zookeeper(4)注册中心
转载来源:http://kswsj.cn/article/gshepc.html

其他资讯