使用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>