Dubbo简单示例

步骤

1. 开启zookeeper注册中心
2. 编写接口
3. 编写服务提供者
4. 编写服务消费者
5. 启动服务提供者
6. 启动服务消费者

接口

  • 使用maven创建项目,打包方式为jar

    4.0.0
    com.dobbo.provider
    dubbo-provider
    0.0.1-SNAPSHOT
    jar

  • 编写简单接口
public interface GBDTService {
    public String ckeckInfo();
}

服务提供者

  • 使用maven创建项目,打包方式为jar,pom中引入接口

    com.dobbo.provider
    dubbo-provider
    0.0.1-SNAPSHOT

  • 编写接口实现类
public class GBDTServiceImpl implements GBDTService {
    public String ckeckInfo() {
        return "返回结果:0";
    }
}
  • 编写配置文件applicationContext.xml

 
    
    
    
    
    
    
    
    
    
    

  • 编写启动类
public class Provider {
    public static void main(String[] args) throws IOException {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        System.out.println(context.getDisplayName() + ": here");
        context.start();
        System.out.println("Provider");
        System.in.read();
    }
}

服务消费者

  • 使用maven创建项目,打包方式为jar,pom中引入接口

    com.dobbo.provider
    dubbo-provider
    0.0.1-SNAPSHOT

编写服务消费者配置文件applicationContext.xml


 
    
    
    
    
    

验证结果

11.png

12.png

dubbo-admin后台查看服务

13.png

你可能感兴趣的:(Dubbo简单示例)