• dubbo的学习使用,第一章


    dubbo在我感觉,是将一个一个系统里面的mvc,再次分离了出来,解耦的作用,与spring无缝集成的一个东西

    代码如下:dubbo的配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
           xmlns="http://www.springframework.org/schema/beans"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
    
        <!-- 提供方应用名称,用于计算依赖关系 -->
        <dubbo:application name="demo-provider" />
        
        <!-- 使用zookeeper注册中心暴露服务地址 -->
        <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
        
        <!-- 使用dubbo协议,在20880端口暴露服务 -->
        <dubbo:protocol name="dubbo" port="20880"/>
        
        <!-- service实现类作为本地的一个bean -->
        <bean id="demoProviderService" class="com.studyDubbo.service.impl.DemoProviderServiceImpl"/>
        
        <!-- 声明需要暴露的服务接口 -->
        <dubbo:service interface="com.studyDubbo.service.DemoProviderService" ref="demoProviderService"/>
    
    </beans>

    service:

    public interface DemoProviderService {
    
        String sayHello(String name);
    }

    servie的实现类:

    public class DemoProviderServiceImpl implements DemoProviderService {
        @Override
        public String sayHello(String name) {
            return "服务001";
        }
    }

    测试类:

    public class test {
    
        public static void main(String[] args) {
            ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"dubbo-demo-provider.xml"});
            context.start();
            System.out.println("服务提供者向zookeeper注册中心注册服务成功(端口20880)");
            try {
                System.in.read();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // press any key to exit
            context.close();
        }
    }

    依赖的jar包:

    <dependencies>
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>dubbo</artifactId>
          <version>2.6.0</version>
        </dependency>
        <dependency>
          <groupId>com.101tec</groupId>
          <artifactId>zkclient</artifactId>
          <version>0.10</version>
        </dependency>
        <dependency>
          <groupId>org.apache.curator</groupId>
          <artifactId>curator-framework</artifactId>
          <version>4.0.1</version>
        </dependency>
        <dependency>
          <groupId>com.alibaba</groupId>
          <artifactId>fastjson</artifactId>
          <version>1.2.46</version>
        </dependency>
        <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
          <version>1.2.17</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.25</version>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-lang3</artifactId>
          <version>3.4</version>
        </dependency>
        <dependency>
          <groupId>io.netty</groupId>
          <artifactId>netty-all</artifactId>
          <version>4.0.35.Final</version>
        </dependency>
      </dependencies>
  • 相关阅读:
    Writing a progress/status report
    五月
    MEGVII 旷视 Brain++ 平台;天元MegEngine 平台简要分析
    地平线4闪退解决办法;地平线4一启动闪退;Forza Horizon 4 won't start
    [已解决]Adobe Reader中禁用“保存更改”对话框;Adobe pdf 要在关闭前保存更改; 另存为;
    想写点新的东西
    IO测试工具:vdbench
    CUDA 线程ID 计算方式;NVIDIA GPGPU;
    csgo 黑屏闪退,解决方法;
    Simulator 和 Emulator 的相同和不同;
  • 原文地址:https://www.cnblogs.com/fuckingPangzi/p/9903825.html
Copyright © 2020-2023  润新知