当前位置: 首页 > news >正文

dubbo 服务中间件 的使用

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

1

3

2

1、在 Service 工程中添加dubbo依赖的jar包。

<!-- 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>

2 在spring的配置文件中添加dubbo的约束,然后使用dubbo:service发布服务。

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

<!-- 配置商品管理的service -->
<context:component-scan base-package="com.shi.service"></context:component-scan>


	<!-- 使用dubbo发布服务 -->
	<!-- 提供方应用信息,用于计算依赖关系 -->
	<dubbo:application name="Graduation-manager" />
	<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" />
	<!-- 用dubbo协议在20880端口暴露服务 -->
	<dubbo:protocol name="dubbo" port="20880" />
	<!-- 声明需要暴露的服务接口 -->
	<dubbo:service interface="com.shi.service.ItemService" ref="itemServiceImp" />

	
</beans>

3 web 添加对dubbo的依赖。

<!-- 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>

4 修改springmvc.xml,在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:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc" 
	xmlns:jdbc="http://www.springframework.org/schema/jdbc"
	xmlns:jee="http://www.springframework.org/schema/jee" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" 
	xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.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.xsd">
	
	<!-- 配置扫描器 -->
	<context:component-scan base-package="com.shi.controller" >
        <!-- 
        use-default-filters="false"
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> --> 
    </context:component-scan>
    
    <!-- 配置springmvc的映射器和适配器 -->
  	<mvc:annotation-driven></mvc:annotation-driven> 

	  <!-- 配置映射器 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<!-- <property name="prefix" value="/WEB-INF/"></property> -->
		<property name="prefix" value="/"></property>
		<property name="suffix" value=".jsp"></property>
	</bean>
	
	<!-- 配置我们的拦截器 -->
	<!-- <mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/**"/>
			<bean class="com.shi.interceptor.LoginInterceptor"></bean>
		</mvc:interceptor>
		<mvc:interceptor>
			<mvc:mapping path="/**"/>
			<bean class="com.shi.interceptor.CheckInterceptor"></bean>
		</mvc:interceptor>
	</mvc:interceptors> -->
	
	
	<!-- 引用dubbo服务 -->
	<dubbo:application name="Graduation-manager-service"></dubbo:application>
	<dubbo:registry protocol="zookeeper" address="127.0.0.1:2181"></dubbo:registry>
	<dubbo:reference interface="com.shi.service.ItemService" id="itemService"></dubbo:reference>
	
</beans>

5 分别在web和service中添加服务器插件 并且启懂zookeeper 和 俩个服务器 就可以 访问我们的服务了

转载于:https://my.oschina.net/u/3677987/blog/1581152

相关文章:

  • [zabbix/自动发现规则]
  • 项目管理:项目中什么叫完成,传统瀑布开发与敏捷开发的完成标准是什么??...
  • php如何发post请求
  • let和var的一个问题
  • aix 查看占用内存高的进程
  • WIN7 U盘安装
  • [完美]原生JS获取浏览器版本判断--支持Edge,IE,Chrome,Firefox,Opera,Safari,以及各种使用Chrome和IE混合内核的浏览器...
  • MongoDB(课时10 数组)
  • vue+vuex+axios+echarts画一个动态更新的中国地图
  • 你绝不能错过的效率神器 —— Alfred
  • Clojure CLR 入门
  • 基于Metronic的Bootstrap开发框架经验总结(8)--框架功能总体界面介绍
  • 配置ssh免密码登陆配置和ssh原理
  • 基于MVC4+EasyUI的Web开发框架经验总结(11)--使用Bundles处理简化页面代码
  • zxing二维码的生成与解码(C#)
  • 【Redis学习笔记】2018-06-28 redis命令源码学习1
  • CNN 在图像分割中的简史:从 R-CNN 到 Mask R-CNN
  • CoolViewPager:即刻刷新,自定义边缘效果颜色,双向自动循环,内置垂直切换效果,想要的都在这里...
  • css的样式优先级
  • Effective Java 笔记(一)
  • ES学习笔记(10)--ES6中的函数和数组补漏
  • exports和module.exports
  • JS变量作用域
  • PHP 程序员也能做的 Java 开发 30分钟使用 netty 轻松打造一个高性能 websocket 服务...
  • php的插入排序,通过双层for循环
  • Python 反序列化安全问题(二)
  • 阿里云购买磁盘后挂载
  • 短视频宝贝=慢?阿里巴巴工程师这样秒开短视频
  • 浮现式设计
  • 关于List、List?、ListObject的区别
  • 基于web的全景—— Pannellum小试
  • 力扣(LeetCode)357
  • 使用前端开发工具包WijmoJS - 创建自定义DropDownTree控件(包含源代码)
  • 我建了一个叫Hello World的项目
  • 阿里云重庆大学大数据训练营落地分享
  • ​​​​​​​​​​​​​​Γ函数
  • ​​​​​​​sokit v1.3抓手机应用socket数据包: Socket是传输控制层协议,WebSocket是应用层协议。
  • #前后端分离# 头条发布系统
  • %@ page import=%的用法
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (第61天)多租户架构(CDB/PDB)
  • (十七)Flask之大型项目目录结构示例【二扣蓝图】
  • (转)甲方乙方——赵民谈找工作
  • (转载)在C#用WM_COPYDATA消息来实现两个进程之间传递数据
  • .Net Redis的秒杀Dome和异步执行
  • .NET Standard、.NET Framework 、.NET Core三者的关系与区别?
  • .NET 回调、接口回调、 委托
  • .NET 设计模式—简单工厂(Simple Factory Pattern)
  • .NET单元测试
  • .stream().map与.stream().flatMap的使用
  • .vimrc php,修改home目录下的.vimrc文件,vim配置php高亮显示
  • @EnableWebMvc介绍和使用详细demo
  • [20171113]修改表结构删除列相关问题4.txt
  • [22]. 括号生成
  • [ARC066F]Contest with Drinks Hard