dubbo学习笔记(1) dubbo入门Hello dubbo

dubbo学习笔记(一) dubbo入门Hello dubbo

Dubbo概述

 

DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。

 

资源文档地址

 

http://dubbo.io/

 

准备ZooKeeper环境

 

 http://lixuguang.iteye.com/blog/2147061

 

接口

 

package demo.service;  
    
public interface DemoService {  
    public void sayHello();  
} 

 

实现类

 

package demo.service;  
  
public class DemoServiceImpl implements DemoService {  
    @Override  
    public void sayHello() {  
        System.out.println("hello dubbo!");  
    }  
}  

 

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
       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  
        ">  
    <dubbo:application name="hello-world-app" />  
    <dubbo:registry  protocol="zookeeper" address="10.125.195.174:2181" />  
    <dubbo:protocol name="dubbo" port="20880" />  
    <dubbo:service interface="demo.service.DemoService"  
                   ref="demoService" />       <!-- 和本地bean一样实现服务 -->  
    <bean id="demoService" class="demo.service.DemoServiceImpl" />  
</beans>  

 

 

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

public class DubboProviderDemo {  
  
    public static void main(String[] args) throws InterruptedException {  
  
        new ClassPathXmlApplicationContext(  
                new String[] {"demo/provider.xml"});  
        while (true){}  
  
    }  
}  

 

 

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
       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  
        ">  
    <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->  
    <dubbo:application name="consumer-of-helloworld-app" />       <!-- 使用multicast广播注册中心暴露发现服务地址 -->  
    <dubbo:registry  protocol="zookeeper" address="10.125.195.174:2181" />         <!-- 生成远程服务代理,可以和本地bean一样使用demoService -->  
    <dubbo:reference id="demoService" interface="demo.service.DemoService" />  
</beans>  

 

import demo.service.DemoService;  
import org.springframework.context.ApplicationContext;  
import org.springframework.context.support.ClassPathXmlApplicationContext;  
  
 
public class DubboComsumeDemo {  
  
    public static void main(String[] args) throws InterruptedException {  
  
        ApplicationContext factory = new ClassPathXmlApplicationContext(  
                new String[] {"demo/comsumer.xml"});  
  
        DemoService demoService = (DemoService) factory.getBean("demoService");  
        demoService.sayHello();  
  
    }  
}  

 

运行

 

先运行 DubboProviderDemo 再运行DubboComsumeDemo ,可以看到在DubboProviderDemo的console中打印 “hello dubbo!”

DUBDUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。BO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的各成员站点。