dubbo,zookpper的使用

使用dubbo。使用rpc协议进行远程调用,直接使用socket通信。传输效率高,都是以二进制形式进行传输的,并且可以统计出系统之间的调用关系、调用次数。

zookpper的安装https://blog.csdn.net/kxj19980524/article/details/84976240

dubbo约束文件https://download.csdn.net/download/kxj19980524/10846337

在项目的parent和service,web层分别引入dubbo的依赖,把spring和netty相关的排除,因为dubbo自动引入spring2.几的依赖,而我们使用的是4.3的所以可能会冲突所以排除掉

 

<!-- dubbo相关 -->

            <dependency>

                  <groupId>com.alibaba</groupId>

                  <artifactId>dubbo</artifactId>

                  <exclusions>

                        <exclusion>

                              <groupId>org.springframework</groupId>

                              <artifactId>spring</artifactId>

                        </exclusion>

                        <exclusion>

                              <groupId>org.jboss.netty</groupId>

                              <artifactId>netty</artifactId>

                        </exclusion>

                  </exclusions>

            </dependency>

            <dependency>

                  <groupId>org.apache.zookeeper</groupId>

                  <artifactId>zookeeper</artifactId>

            </dependency>

            <dependency>

                  <groupId>com.github.sgroschupf</groupId>

                  <artifactId>zkclient</artifactId>

            </dependency>

然后在service的spring配置文件中发布服务,别忘了在头信息引入dubbo的标签和在eclipse中配置本地约束文件,就我上面的那个路径key填配置文件中的头信息那个路径

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
    http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd">

    <!-- 配置包扫描器 -->
    <context:component-scan base-package="cn.e3mall.service"/>
    
    <!-- 使用dubbo发布服务 -->
    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="e3-manager" />    <!--这是配置哪个工程发布的服务,name最好就写成项目名就可以了,每个服务的这个名称不能重复-->
    <dubbo:registry protocol="zookeeper" address="192.168.25.160:2181" />   <!--配置zookeeper  地址就是安装到linux的ip和端口要是集群版的话后面可以跟多个以逗号隔开就行-->
    <!-- 用dubbo协议在20880端口暴露服务,每个服务的端口不能重复,再有一个服务就改改,20881或者其它的,name就是dubbo固定的 -->
    <dubbo:protocol name="dubbo" port="20880" />
    <!-- 声明需要暴露的服务接口,ref为前面接口的实现类. -->
    <dubbo:service interface="cn.e3mall.service.ItemService" ref="itemServiceImpl" timeout="600000"/><!--这个时间是设置超时时间,如果在一秒内没有响应,会重试三次然后报错,这个主要是使用debug的时候一秒肯定连部上所有需要设置时间-->
</beans>

 

表现层调用服务 ,在mvc配置文件中调用

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <context:component-scan base-package="cn.e3mall.controller" />
    <mvc:annotation-driven />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
    <!-- 配置资源映射 -->
    <mvc:resources location="/css/" mapping="/css/**"/>
    <mvc:resources location="/js/" mapping="/js/**"/>
    <!-- 引用dubbo服务 -->
    <dubbo:application name="e3-manager-web"/>   <!--这个也是给调用服务起个名-->
    <dubbo:registry protocol="zookeeper" address="192.168.25.160:2181"/>     <!--这儿也是配调用zookpper的ip端口-->
    <dubbo:reference interface="cn.e3mall.service.ItemService" id="itemService" /><!--调用哪个接口-->
</beans>

然后先启动服务层,再启动web层进行测试,访问controller的时候会发现报错,这个说的是实体类没有序列化,因为dubbo传输是通过socket传输的,是以二进制的形式,所以需要给实体类进行序列化,在pojo的实体类上实现序列化

如果启动项目的时候发现卡着不走了,就是没有出现下面这句话,这时候需要加入log日志信息,再启动就能看到报错信息了再进行解决

log4j配置文件https://download.csdn.net/download/kxj19980524/10846448

debug的使用,模块分开之后使用debug的话会发现不好使,原因是找不到源代码,需要进行设置

先把默认的删除掉再添加自己需要的,就好了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值