SpringBoot2.0之整合Dubbo
Dubbo支持协议
Dubbo支持dubbo、rmi、hessian、http、webservice、thrift、redis等多种协议,但是Dubbo官网是推荐我们使用Dubbo协议的。
Spring Cloud 项目feign客户端 继承依赖方式实现重构项目
jar: 打成jar包
pom:依赖被被人继承的 公共依赖 字符模块
war:达成一个web项目 里面包含jar包、WEB-INF
toov5-dubbo-parent pom
toov5-public-api-service pom 提供会员接口 jar类型 pom项目没有Java代码的哦
toov5-api-member-service
toov5-api-member-service-impl 会员接口实现类(这个不是公开的) (点击parent创建的,需要引入 实现的interface )
toov5-dubbo-order-web jar(springboot) 订单项目 调用会员项目 ps:订单调用会员时候 引入公共接口 底层调用dubbo协议 帮助实现 *(dubbo原理 拿到类的class的地址信息,反射。)
parent引入共同依赖:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>toov5-dubbo-parent </groupId>
<artifactId>dubbo-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<curator-framework.version>4.0.1</curator-framework.version>
<zookeeper.version>3.4.13</zookeeper.version>
<dubbo.starter.version>0.2.0</dubbo.starter.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.starter.version}</version>
</dependency> <!-- <dependency 在上面已经实现好了>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>${curator-framework.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>${zookeeper.version}</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> -->
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> <modules>
<module>toov5-api-member-service-impl</module>
<module>toov5-public-api-service</module>
</modules>
</project>
点击parent 创建 maven pom :toov5-public-api-service (公共接口maven model) 点击 toov5-public-api-service 创建 toov5-api-member-service jar (写接口 interface)
点击parent 创建 maven jar : toov5-api-member-service-impl 并且 引入: toov5-api-member-service 的依赖 dependency
接口:
package com.toov.api.member.service; public interface MemberService { public String getUser(); }
实现类:
package com.toov.api.member.service.impl; import com.alibaba.dubbo.config.annotation.Service;
import com.toov.api.member.service.MemberService; @Service
public class MemberServiceImpl implements MemberService { public String getUser() {
System.out.println("订单服务调用会员服务");
return "订单服务调用会员服务成功";
} }
启动类:
package com.toov.api.member.service.impl; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo; @EnableDubbo
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
yml:
server:
port: 8080
dubbo:
application:
name: member
#表示采用的dubbo协议
protocol:
name: dubbo
#发布的端口号
port: 20880
registry:
address: zookeeper://192.168.91.5:2181
PS:如果需要写版本号的 springboot没有帮你整合 如果不需要写版本号 已经帮忙整合了
Dubbo发布时候 采用注解方式! 使用 @Service注解 进行发布服务
记得采用 Dubbo 而不是 spring 的注解!
区别: spring 提供的 是注入到Spring容器中 dubbo是注册到注册中心去!
扫的实现类 注册到dubbo 注册中心中去
启动效果:
点击parent 创建 toov5-dubbo-order-web jar 然后引入接口依赖!
package toov5.order.controller; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import com.alibaba.dubbo.config.annotation.Reference;
import com.toov.api.member.service.MemberService; @RestController
public class OrderController {
@Reference //dubbo提供的 而不是@Autowired
private MemberService memberService;
@RequestMapping("/orde")
public String orderToMember() {
return memberService.getUser(); } }
启动类:
package toov5.order.controller; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
@EnableDubbo
@SpringBootApplication
public class AppOrder {
public static void main(String[] args) {
SpringApplication.run(AppOrder.class, args);
}
}
yml
server:
port: 8082 #tomcat端口号
###dubbo 注册服务名称
dubbo:
application:
name: order
registry:
address: zookeeper://192.168.91.5:2181
consumer: #调用服务的超时时间
timeout: 5000
运行并且访问:
大家可以多启动几个 发布服务端口 然后 玩玩 就集群效果 我就不做展示了
SpringBoot2.0之整合Dubbo的更多相关文章
- SpringBoot2.0之整合Kafka
maven依赖: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...
- SpringBoot2.0之整合Apollo
Spring Boot客户端对接阿波罗服务器端 核心源码都在这个压缩包里面 封装好了环境 运行shell脚本就ok了 下面进入到本地maven仓库: 远程仓库apollo的jar包 只能打包到本地或者 ...
- SpringBoot2.0之整合ElasticSearch
就类比数据库到时候去实现 服务器端配置 集群名字 与yml名字一致 pom: <project xmlns="http://maven.apache.org/POM/4.0.0&qu ...
- SpringBoot2.0之整合ActiveMQ(发布订阅模式)
发布订阅模式与前面的点对点模式很类似,简直一毛一样 注意:发布订阅模式 先启动消费者 公用pom: <project xmlns="http://maven.apache.org/PO ...
- SpringBoot2.0之整合ActiveMQ(点对点模式)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 基于 SpringBoot2.0+优雅整合 SpringBoot+Mybatis
SpringBoot 整合 Mybatis 有两种常用的方式,一种就是我们常见的 xml 的方式 ,还有一种是全注解的方式.我觉得这两者没有谁比谁好,在 SQL 语句不太长的情况下,我觉得全注解的方式 ...
- springboot2.0 Mybatis 整合
原文:https://blog.csdn.net/Winter_chen001/article/details/80010967 环境/版本一览: 开发工具:Intellij IDEA 2017.1. ...
- 每天学点SpringCloud(一):使用SpringBoot2.0.3整合SpringCloud
最近开始学习SpringCloud,在此把我学习的过程记录起来,跟大家分享一下,一起学习.想学习SpringCloud的同学赶快上车吧. 本次学习使用得SpringBoot版本为2.0.3.RELEA ...
- SpringBoot2.0.3整合Quartz2.3.0实现定时任务
转载:https://www.cnblogs.com/ealenxie/p/9134602.html 关于别人写的quartz学习的地址:https://blog.csdn.net/lkl_csdn/ ...
随机推荐
- spring batch的使用和定时器Quart的使用
Spring Batch是一个基于Spring的企业级批处理框架,它通过配合定时器Quartz来轻易实现大批量的数据读取或插入,并且全程自动化,无需人员管理. 在使用spring batch之前,得对 ...
- 2017.2.12 开涛shiro教程-第七章-与Web集成
2017.2.9 开涛shiro教程-第七章-与Web集成(一) 原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. ...
- hql小经验
hql如果查了子对象的属性,那么hql不允许子对象为空!
- 安装centos出错
在vitural Box中安装centos,出现了如下问题,重新下一遍就好了,如果网速很慢,下载的过程中总是断断续续的就容易出现下载文件损坏的问题. Could not get the storage ...
- EAI G4-lidar ROS配置
(1)使用命令创建 ydlidar_ws 工作空间,并将 G4 资料包内的 ROS 驱动包 ydlidar 下载到ydlidar_ws/src 目录下,切换到 ydlidar_ws 工作空间下并重新进 ...
- Struts2学习九----------处理结果类型(input)
© 版权声明:本文为博主原创文章,转载请注明出处 Struts2处理结果类型 - SUCCESS:Action正确的执行完成,返回相应的视图,success是name属性的默认值 - ERROR:表示 ...
- Lua数据库访问
© 版权声明:本文为博主原创文章,转载请注明出处 1.代码 luasql = require "luasql.mysql" --创建环境对象 env = luasql.mysql( ...
- 这样好用的ReactiveCocoa,根本停不下来【转载】
前戏我个人非常推崇ReactiveCocoa,它就像中国的太极,太极生两仪,两仪生四象,四象生八卦,八卦生万物.ReactiveCocoa是一个高度抽象的编程框架,它真的很抽象,初看你不知道它是要干嘛 ...
- 牛牛有一个鱼缸。鱼缸里面已经有n条鱼,每条鱼的大小为fishSize[i] (1 ≤ i ≤ n,均为正整数),牛牛现在想把新捕捉的鱼放入鱼缸。鱼缸内存在着大鱼吃小鱼的定律。经过观察,牛牛发现一条鱼A的大小为另外一条鱼B大小的2倍到10倍(包括2倍大小和10倍大小),鱼A会吃掉鱼B。考虑到这个,牛牛要放入的鱼就需要保证:1、放进去的鱼是安全的,不会被其他鱼吃掉 2、这条鱼放进去也不能吃掉其他鱼
// ConsoleApplication5.cpp : 定义控制台应用程序的入口点. // #include<vector> #include<algorithm> #inc ...
- 地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...