17、SpringBoot------整合dubbo
SpringBoot整合Dubbo+Zookeaper
1.安装运行zookeeper
(1)下载zookeeper
官网:http://zookeeper.apache.org/
(2)解压缩
(3)修改配置文件
拷贝zoo_sample.cfg重命名为zoo.cfg
修改配置文档
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=../data # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1
创建data文件夹
(4)cmd启动zkServer.sh
2.安装dubbo web管理客户端
(1)下载Duboo OPS
下载地址:https://github.com/apache/incubator-dubbo-ops/tree/master
(2)修改配置
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#server.port=7001
spring.velocity.cache=false
spring.velocity.charset=UTF-8
spring.velocity.layout-url=/templates/default.vm
spring.messages.fallback-to-system-locale=false
spring.messages.basename=i18n/message
spring.root.password=root
spring.guest.password=guestdubbo.registry.address=zookeeper://127.0.0.1:2181
(3)maven打包dubbo-admin
(4)启动生成jar
(5)访问http://localhost:7001/
3.安装dubbo监控服务中心
(1)maven打包dubbo-monitor-simple
(2)解压dubbo-monitor-simple-2.0.0-assembly.tar.gz
(3)修改配置文件
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.dubbo.container=log4j,spring,registry,jetty-monitor
dubbo.application.name=simple-monitor
dubbo.application.owner=dubbo
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://127.0.0.1:2181
#dubbo.registry.address=redis://127.0.0.1:6379
#dubbo.registry.address=dubbo://127.0.0.1:9090
dubbo.protocol.port=7070
dubbo.jetty.port=8080
dubbo.jetty.directory=${user.home}/monitor
dubbo.charts.directory=${user.home}/monitor/charts
dubbo.statistics.directory=${user.home}/monitor/statistics
dubbo.log4j.file=logs/dubbo-monitor-simple.log
dubbo.log4j.level=WARN
(4)启动start.bat
(5)访问http://localhost:8080/
4.整合springboot
(1)新建Maven项目:d_api :一个公用service的api
新建一个接口:HelloService
package com.xm.dubbo.service;public interface HelloService {String sayHello();}
(2)新建Springboot项目:Hello_Producer
参考链接:https://github.com/apache/incubator-dubbo-spring-boot-project
添加依赖
<?xml version="1.0" encoding="UTF-8"?> <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>com.xm.dubbo</groupId><artifactId>hello_producer</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>hello_producer</name><description>This is a Web about springcloud</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.alibaba.boot</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>0.2.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.xm.dubbo</groupId><artifactId>d_api</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
修改配置文件
dubbo.application.name=hello_producer dubbo.registry.protocol=zookeeper dubbo.registry.address=127.0.0.1:2181 dubbo.scan.base-packages=com.xm.dubbo.service dubbo.protocol.name=dubbo dubbo.protocol.port=20080 dubbo.monitor.protocol=registry
新建HelloServiceImpl
package com.xm.dubbo.service.impl;import org.springframework.stereotype.Component;import com.alibaba.dubbo.config.annotation.Service; import com.xm.dubbo.service.HelloService;@Service @Component public class HelloServiceImpl implements HelloService {@Overridepublic String sayHello() {System.out.println("生产者已被调用!");return "Hello dubbo!";}}
项目入口添加@EnableDubbo注解
package com.xm.dubbo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;@EnableDubbo @SpringBootApplication public class HelloProducerApplication {public static void main(String[] args) {SpringApplication.run(HelloProducerApplication.class, args);} }
(3)新建Springboot项目:Hello_Consumer
添加依赖
<?xml version="1.0" encoding="UTF-8"?> <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>com.xm.dubbo</groupId><artifactId>hello_consumer</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>hello_consumer</name><description>This is a Web about springcloud</description><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>com.alibaba.boot</groupId><artifactId>dubbo-spring-boot-starter</artifactId><version>0.2.0</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>com.xm.dubbo</groupId><artifactId>d_api</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
修改配置文件
server.port=8081dubbo.application.name=hello_consumer dubbo.registry.protocol=zookeeper dubbo.registry.address=127.0.0.1:2181 dubbo.monitor.protocol=registry
新建HelloController
package com.xm.dubbo.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;import com.alibaba.dubbo.config.annotation.Reference; import com.xm.dubbo.service.HelloService;@RestController public class HelloController {@Referenceprivate HelloService helloService;@GetMapping("/hello")public String sayHello() {return helloService.sayHello();}}
项目入口添加@EnableDubbo注解
package com.xm.dubbo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;@EnableDubbo @SpringBootApplication public class HelloConsumerApplication {public static void main(String[] args) {SpringApplication.run(HelloConsumerApplication.class, args);} }
转载于:https://www.cnblogs.com/TimerHotel/p/springboot17.html
17、SpringBoot------整合dubbo相关推荐
- 搭建大型分布式服务(十四)SpringBoot整合dubbo starter
一.本文要点 接上文,我们已经把SpringBoot整合mybatis+Hikari+es+redis+kafka了,本文将介绍SpringBoot如何整合dubbo.系列文章完整目录 dubbo注解 ...
- Springboot整合Dubbo简单示例
Springboot 整合dubbo: 1 简介 Dubbo是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次访问量支持,并被广泛应用于阿里巴巴集团的 ...
- spring整合dubbo和springboot整合dubbo,实现服务暴露区别
spring整合dubbo的时候实现服务暴露是这么做的,在xml里配置 那么springboot整合dubbo的时候,是通过dubbo的@Service 注解实现的 之前我们是通过@Autowired ...
- SpringBoot整合Dubbo+Zookeeper进行分布式搭建系统
QUESTIONl:SpringBoot整合Dubbo+Zookeeper进行分布式搭建系统? ANSWER: 一:创建项目模块 1.1.创建一个Empty Project 名称:Dubbo 1.2. ...
- springboot整合dubbo\zookeeper做注册中心
springboot整合dubbo发布服务,zookeeper做注册中心.前期的安装zookeeper以及启动zookeeper集群就不说了. dubbo-admin-2.5.4.war:dubbo服 ...
- springBoot整合Dubbo使用与采坑
参考:springBoot整合Dubbo 下载源码到:我的下载中心去下
- springboot整合dubbo时连接zookeeper——天坑
本文主要针对使用springboot整合dubbo框架时使用zookeeper作为注册中心,在服务启动连接zookeeper产生的问题做一个详细的讲解. 主要针对两个异常 (1)java.lang.I ...
- 【SpringBoot整合Dubbo和Zookeeper】
本笔记内容为狂神说SpringBoot集成Dubbo和Zookeeper部分 目录 一.Dubbo dubbo基本概念 调用关系说明 二.Dubbo环境搭建 三.Window下安装zookeeper ...
- 【SpringBoot】12.SpringBoot整合Dubbo+Zookeeper
1. 准 备 1.1 Dubbo 简介 Apache Dubbo 是一款高性能.轻量级的开源 Java RPC 框架,它提供了三大核心能力:面向接口的远程方法调用.智能容错和 负载均衡.以及服务自动注 ...
- 解决springboot整合dubbo中No provider available from registry 127.0.0.1:2181 for service x.x.x on consumer
解决springboot整合dubbo中No provider available from registry 127.0.0.1:2181 for service x.x.x on consumer ...
最新文章
- ROS关于cv_brige的使用
- harmonyos2.0如何申请,华为鸿蒙HarmonyOS2.0手机开发者Beta版公测申请地址方法_专题_53货源网...
- [转]解决Android studio升级到3.5的一些问题
- jmeter测试java服务_Jmeter 测试 JMS (Java Message Service)/ActiveMQ 性能
- 洛谷P2822 组合数问题
- Prototype模式
- 天画-codeMaker组件化架构升级实践
- 使用sp_executesql存储过程执行动态SQL查询
- 接口测试常用工具及测试方法(超全)干货
- HDU2546 饭卡【贪心+0-1背包】
- iOS开发之国际化(本地化)
- PHP直播聊天室源码/财经直播源码/房间多开/游客互动/聊天审核
- nutch ajax mysql_Nutch爬取Ajax请求的动态网页
- 【预测模型】基于麻雀算法优化最小二乘支持向量机实现数据分类matlab代码
- AspUpload组件的方法中文说明
- px4仿真无法起飞问题(Failsafe enabled: no datalink)
- Spark与大数据处理技术实践
- 移远BC35-G配置网络连接阿里云MQTT发送数据
- 数据库的备份恢复和SQL语句
- 四个有意义的哲理故事
热门文章
- rsync、scp “tab” 卡顿问题
- zabbix监控TCP连接数
- Nginx+keepalived高可用配置实战
- ubuntu安装ElasticSearch-head插件
- 使用Ecliplse时,对导入package的顺序进行设定
- 错误: 15138删除对于用户失败,数据库主体在该数据库中拥有架构,无法删除。解决方法(转)
- mysql中更改字符集为utf8mysql中文输入不了问题解决
- 如何实现vue前端跨域,proxyTable解决开发环境前端跨域问题
- 在windows下安装node-sass失败,提示\node-sass: Command failed,解决方案
- 打开 VMware Workstation 14 Pro 中的虚拟机出现 “此主机支持 Intel VT-x,但 Intel VT-x 处于禁用状态” 解决方法