Apache Dubbo 项目教程

Apache Dubbo 项目教程

dubboThe java implementation of Apache Dubbo. An RPC and microservice framework.项目地址:https://gitcode.com/gh_mirrors/dubbo11/dubbo

1. 项目的目录结构及介绍

Apache Dubbo 是一个高性能的 Java RPC 框架,其 GitHub 仓库的目录结构如下:

dubbo/
├── dubbo-cluster/
├── dubbo-common/
├── dubbo-compatible/
├── dubbo-compiler/
├── dubbo-config/
├── dubbo-configcenter/
├── dubbo-container/
├── dubbo-demo/
├── dubbo-dependencies/
├── dubbo-dependencies-bom/
├── dubbo-distribution/
├── dubbo-filter/
├── dubbo-maven-plugin/
├── dubbo-metadata/
├── dubbo-metrics/
├── dubbo-monitor/
├── dubbo-registry/
├── dubbo-remoting/
├── dubbo-rpc/
├── dubbo-serialization/
├── dubbo-test/
├── dubbo-validation/
├── dubbo-bom/
├── dubbo-build-tools/
├── dubbo-filter/
├── dubbo-plugin/
├── dubbo-registry/
├── dubbo-remoting/
├── dubbo-rpc/
├── dubbo-serialization/
├── dubbo-test/
├── dubbo-validation/
└── dubbo-bom/

主要目录介绍:

  • dubbo-cluster: 集群容错模块。
  • dubbo-common: 公共工具模块。
  • dubbo-config: 配置模块。
  • dubbo-demo: 示例代码。
  • dubbo-dependencies: 依赖管理模块。
  • dubbo-distribution: 发布包模块。
  • dubbo-registry: 注册中心模块。
  • dubbo-remoting: 远程通信模块。
  • dubbo-rpc: RPC 协议模块。
  • dubbo-serialization: 序列化模块。

2. 项目的启动文件介绍

Dubbo 项目的启动通常涉及以下几个步骤:

  1. 定义服务接口

    package org.apache.dubbo.samples.api;
    
    public interface GreetingsService {
        String sayHi(String name);
    }
    
  2. 实现服务接口

    package org.apache.dubbo.samples.provider;
    
    import org.apache.dubbo.samples.api.GreetingsService;
    
    public class GreetingsServiceImpl implements GreetingsService {
        @Override
        public String sayHi(String name) {
            return "Hi, " + name;
        }
    }
    
  3. 配置服务提供者

    <dubbo:application name="hello-world-app"/>
    <dubbo:registry address="multicast://224.5.6.7:1234"/>
    <dubbo:protocol name="dubbo" port="20880"/>
    <dubbo:service interface="org.apache.dubbo.samples.api.GreetingsService" ref="greetingsService"/>
    <bean id="greetingsService" class="org.apache.dubbo.samples.provider.GreetingsServiceImpl"/>
    
  4. 启动服务提供者

    import org.apache.dubbo.config.RegistryConfig;
    import org.apache.dubbo.config.ApplicationConfig;
    import org.apache.dubbo.config.ProtocolConfig;
    import org.apache.dubbo.config.ServiceConfig;
    import org.apache.dubbo.samples.api.GreetingsService;
    import org.apache.dubbo.samples.provider.GreetingsServiceImpl;
    
    public class Provider {
        public static void main(String[] args) throws Exception {
            ServiceConfig<GreetingsService> service = new ServiceConfig<>();
            service.setApplication(new ApplicationConfig("hello-world-app"));
            service.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
            service.setProtocol(new ProtocolConfig("dubbo", 20880));
            service.setInterface(GreetingsService.class);
            service.setRef(new GreetingsServiceImpl());
            service.export();
            System.out.println("Provider started");
            System.in.read(); // 按任意键退出
        }
    }
    

dubboThe java implementation of Apache Dubbo. An RPC and microservice framework.项目地址:https://gitcode.com/gh_mirrors/dubbo11/dubbo

  • 30
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

祝珺月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值