1. zookpeer搭建

    下载zookeeper-3.4.6,cd ./conf/   ,  cp   zoo_sample.cfg   zoo.cfg

                                     

    dubbo-Admin控制台+zookeeper环境搭建_第1张图片

     ./bin/zkServer.sh start 启动zookpeer服务

  2. dubboAdmain控制台搭建

    下载dubbo-admin.war,解压后放到tomcat的运行目录下,修改配置WEB-INF/dubbo.properties

    文件:

    dubbo.registry.address=zookeeper://192.168.1.201:2181,注意改成自己的地址
    dubbo.admin.root.password=root
    dubbo.admin.guest.password=guest

    这里,我们为一个应用发布两个提供者在不同的机器上,即使它们中有一台机器挂了,服务端也可以正常访问。

    package com.service;
    import java.util.List;

    /**
     * @描述 :
     * @创建者 : guoxiaopeng
     * @创建时间 : 2017-7-11 下午12:44:45
     */
    public interface DemoService {
        String sayHello(String name);  
        
        public List getUsers();  
    }


     package com.service;

import java.util.ArrayList;
import java.util.List;

import com.domain.User;


/**
 * @描述 :
 * @创建者 : guoxiaopeng
 * @创建时间 : 2017-7-11 下午12:45:12
 */
public class DemoServiceImpl implements DemoService{
    public String sayHello(String name) {  
        return "Hello " + name;  
    }  
 
    public List getUsers() {  
        List list = new ArrayList();  
        User u1 = new User();  
        u1.setName("jack");  
        u1.setAge(20);  
        u1.setSex("m");  
 
        User u2 = new User();  
        u2.setName("tom");  
        u2.setAge(21);  
        u2.setSex("m");  
 
        User u3 = new User();  
        u3.setName("rose");  
        u3.setAge(19);  
        u3.setSex("w");  
 
        list.add(u1);  
        list.add(u2);  
        list.add(u3);  
        return list;  
    }  
}

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @描述 :
 * @创建者 : guoxiaopeng
 * @创建时间 : 2017-7-11 下午1:05:57
 */
public class Provider {

    public static void main(String[] args) throws Exception {  
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(  
                new String[] { "spring-config.xml" });  
        context.start();  
        System.in.read(); // 为保证服务一直开着,利用输入流的阻塞来模拟  
    }  
}

pom.xml

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  provider1
  dubbo-provider1
  war
  0.0.1-SNAPSHOT
  dubbo-provider1 Maven Webapp
  http://maven.apache.org
 
        3.0.5.RELEASE
 

 
   
      junit
      junit
      3.8.1
      test
   

   
       
            org.springframework
            spring-test
            ${spring.version}
       

       
            org.springframework
            spring-aop
            ${spring.version}
       

       
            org.springframework
            spring-core
            ${spring.version}
       

       
            org.springframework
            spring-beans
            ${spring.version}
       

       
            org.springframework
            spring-context
            ${spring.version}
       

       
            org.springframework
            spring-orm
            ${spring.version}
       

       
            org.springframework
            spring-webmvc
            ${spring.version}
       

       
            org.springframework
            spring-tx
            ${spring.version}
       

       
            org.springframework
            spring-jdbc
            ${spring.version}
       

       
            org.opensymphony.quartz
            quartz
            1.6.1
       

       
            javax.transaction
            jta
            1.1
       

       
        
       
       
            com.alibaba
            dubbo
            2.5.3  
           
               
                    org.springframework
                    spring
               

           

       

       
        
       
         
            com.github.sgroschupf  
            zkclient  
            0.1  
       

       
 

 
    dubbo-provider1
 



spring-config.xml











    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
    default-autowire="byName">
 
     
     
 
     
     

 
     
     
 
     
            ref="demoService" />  
          
          
     
     
 
 

spring-config-rpc.xml











    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
    default-autowire="byName">
 
     
     
 
     
     

 
     
     
 
     
            ref="demoService" />  
          
          
     
     
 
 



生成者项目层级结构


dubbo-Admin控制台+zookeeper环境搭建_第2张图片


服务端代码:


ClientTest.java

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.service.DemoService;

/**
 * @描述 :
 * @创建者 : guoxiaopeng
 * @创建时间 : 2017-7-12 上午11:26:27
 */
public class ClientTest {

    public static void main(String[] args) {
        ApplicationContext app=new ClassPathXmlApplicationContext("spring-config.xml");
        DemoService demoService= (DemoService) app.getBean("demoService");
        String sayHello = demoService.sayHello("hello");
        System.out.println(sayHello);
    }
}

spring-config-rpc.xml



    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans        http://www.springframework.org/schema/beans/spring-beans.xsd        http://code.alibabatech.com/schema/dubbo        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"
    default-autowire="byName">
 
   
 
 
 
    
    

         
   
 

spring-config.xml


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
    default-autowire="byName">
    
    
      


pom.xml


  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  consumer
  dubbo-consumer
  war
  0.0.1-SNAPSHOT
  dubbo-consumer Maven Webapp
  http://maven.apache.org
  
        3.0.5.RELEASE
 

 
   
      junit
      junit
      3.8.1
      test
   

   
       
            org.springframework
            spring-test
            ${spring.version}
       

       
            org.springframework
            spring-aop
            ${spring.version}
       

       
            org.springframework
            spring-core
            ${spring.version}
       

       
            org.springframework
            spring-beans
            ${spring.version}
       

       
            org.springframework
            spring-context
            ${spring.version}
       

       
            org.springframework
            spring-orm
            ${spring.version}
       

       
            org.springframework
            spring-webmvc
            ${spring.version}
       

       
            org.springframework
            spring-tx
            ${spring.version}
       

       
            org.springframework
            spring-jdbc
            ${spring.version}
       

       
            org.opensymphony.quartz
            quartz
            1.6.1
       

       
            javax.transaction
            jta
            1.1
       

       
        
       
       
            com.alibaba
            dubbo
            2.5.3  
           
               
                    org.springframework
                    spring
               

           

       

       
        
       
         
            com.github.sgroschupf  
            zkclient  
            0.1  
       

       
        
       
            myDubbo
            myDubbo
            0.0.2
       

       
 

 
    dubbo-consumer
 




浏览器访问地址:http://127.0.0.1:8080/dubboAdmin/

提供者和服务端

dubbo-Admin控制台+zookeeper环境搭建_第3张图片

dubbo-Admin控制台+zookeeper环境搭建_第4张图片