Dubbo初始问题怎么解决

发布时间:2023-03-01 17:53:43 作者:iii
来源:亿速云 阅读:135

本篇内容主要讲解“Dubbo初始问题怎么解决”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Dubbo初始问题怎么解决”吧!

Dubbo架构

Dubbo初始问题怎么解决

消费者:调用提供者,但是不能直接调,需要借助注册中心

节点角色说明

过程

0start:服务的提供者要运行在一个容器里面,比如运行在tomcat里面,需要将tomcat启动起来。

1注册:启动起来之后,该服务就会注册到注册中心里(将服务调用的ip、端口、服务发布url放到注册中心里面去。)。

2.subscribe:我想调用提供者提供的服务,我这时去找注册中心去找(告诉服务中心将服务的相关信息给消费者)

3.notify:消费者要一次服务,注册中心给一次。

这时消费者拿到服务的信息

4.invoke:就是rpc的过程,进行调用。不用我们管,dubbo内部自动实现。

5.Monitor:服务监控。统计某个服务调用了多少次。

asyn:异步。sync:同步。只有rpc调用时同步的,其他的都是异步的。

Zookeeper安装

先安装java1.8

解压,进入配置文件夹,复制配置文件,并修改里面的配置使其生效。复制会话窗口,创建目录,将该目录复制修改到配置文件里面。启动zk

zk默认端口为2181

Mode:standalone(当前没有搭建集群,是单节点在运行)

Dubbo快速入门

Dubbo初始问题怎么解决

注意这里的controller调用service是远程调用,是两个工程分别部署在两台机器上。

jar包依赖

        <!--Dubbo的起步依赖,版本2.7之后统一为rg.apache.dubb -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <!--ZooKeeper客户端实现 -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>${zookeeper.version}</version>
        </dependency>
        <!--ZooKeeper客户端实现 -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>${zookeeper.version}</version>
        </dependency>

Dubbo初始问题怎么解决

开始配置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://dubbo.apache.org/schema/dubbo" 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://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

   <!--spring包扫描-->
   <!--<context:component-scan base-package="com.itheima.service"/>-->

   <!--dubbo的配置-->
   <!--1、配置项目的名称,唯一-->
   <dubbo:application name="dubbo-service"/>
   <!--2、配置注册中心的地址-->
   <dubbo:registry address="zookeeper://101.42.248.44:2181"/>
   <!--3、配置dubbo包扫描-->
   <dubbo:annotation package="com.itheima.service.impl"/>


</beans>

Dubbo初始问题怎么解决

添加spring的配置,让其扫描加载刚在配置dubbo的配置文件applicationContext.xml

Dubbo初始问题怎么解决

配置zk

上面的扫描时扫面springmvc的注解

<?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://dubbo.apache.org/schema/dubbo"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
         http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

    <!--打开注解驱动-->
    <mvc:annotation-driven/>
    <!--扫描包-->
    <context:component-scan base-package="com.itheima.controller"/>

    <!--dubbo的配置-->
    <!--1、配置项目的名称,唯一-->
    <dubbo:application name="dubbo-web">
        <dubbo:parameter key="qos.port" value="33333"/>
    </dubbo:application>
    <!--2、配置注册中心的地址-->
    <dubbo:registry address="zookeeper://101.42.248.44:2181"/>
    <!--3、配置dubbo包扫描-->
    <dubbo:annotation package="com.itheima.controller"/>
</beans>

Dubbo初始问题怎么解决

创建一个公共接口模块,减少重复代码开发,易于接口调用

到此,相信大家对“Dubbo初始问题怎么解决”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. Dubbo应用迁移到Kubernetes
  2. Dubbo 在 K8s 下的思考

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

dubbo

上一篇:base64编码原理是什么

下一篇:SpringBoot项目多层级多环境yml设计的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》