博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Dubbo的使用入门
阅读量:5878 次
发布时间:2019-06-19

本文共 5413 字,大约阅读时间需要 18 分钟。

一、包引入

1、父模块pom.xml中加入依赖:

    
com.alibaba.boot
dubbo-spring-boot-starter
0.2.0

 

我这里还引入了SpringBoot和一些常用组件 

org.springframework.boot
spring-boot-starter-parent
2.0.4.RELEASE
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
org.springframework.boot
spring-boot-devtools
2.0.4.RELEASE
org.projectlombok
lombok
1.16.22
org.springframework.boot
spring-boot-starter-data-jpa
2.0.4.RELEASE
com.alibaba.boot
dubbo-spring-boot-starter
0.2.0
org.springframework.boot
spring-boot-starter-web
com.alibaba
fastjson
1.2.51

 

 

2、服务提供者子模块的application.properties中加入下列配置

server.port=8084spring.application.name=dubbo-provider-usersdubbo.application.name=dubbo-provider-usersdubbo.registry.protocol=zookeeperdubbo.registry.address=172.16.4.132:2181|172.16.4.131:2181|172.16.4.133:2181dubbo.protocol.name=dubbodubbo.protocol.port=20884dubbo.scan.base-packages=com.yungoal.usersservicedubbo.consumer.timeout=3600000dubbo.provider.timeout=3600000dubbo.registry.timeout=3600000dubbo.consumer.retries=5dubbo.provider.retries=5dubbo.consumer.callbacks=3600000dubbo.provider.callbacks=3600000dubbo.consumer.check=falsedubbo.registry.check=falsedubbo.application.qos-enable=false

发部服务,可以这样:

import com.alibaba.dubbo.config.annotation.Service;import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;import javax.validation.constraints.NotNull;import java.util.List;@Service(version = "1.0.0")@RestControllerpublic class TenantProvider implements ITenantProvider {    @Resource    private TenantBusiness tenantBusiness;    @Override    public FuncResultBo
createCcUser(CcUserVo user, ApiKeyVo api_info) { return tenantBusiness.createCcUser(user, api_info); }}

 

3、服务提供者SpringBoot启动类中加入:@EnableDubbo属性标记,例如我的:

package com.yungoal.usersservice;import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.autoconfigure.domain.EntityScan;import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import org.springframework.data.jpa.repository.config.EnableJpaRepositories;@Configuration@SpringBootApplication()@ComponentScan({
"com.yungoal"})@EnableJpaRepositories(basePackages = {"com.yungoal.repository"})@EnableAutoConfiguration@EntityScan("com.yungoal.domain.po")@EnableDubbopublic class UsersProviderApplication { public static void main(String[] args) { SpringApplication.run(UsersProviderApplication.class, args); }}

 

4、消费者的application.properties中加入:

spring.application.name=dubbo-consumer-backendsyncdubbo.application.name=dubbo-consumer-backendsyncdubbo.registry.protocol=zookeeperdubbo.registry.address=172.16.4.131:2181|172.16.4.132:2181|172.16.4.133:2181dubbo.scan.base-packages=com.yungoal.syncbackenddubbo.protocol.name=dubbodubbo.protocol.port=20880dubbo.consumer.timeout=3600000dubbo.provider.timeout=3600000dubbo.registry.timeout=3600000dubbo.consumer.retries=5dubbo.provider.retries=5dubbo.consumer.callbacks=3600000dubbo.provider.callbacks=3600000dubbo.consumer.check=truedubbo.registry.check=falsedubbo.application.qos-enable=false

5、在消费者启动类中,可以加入EnableDubbo属性标记

@SpringBootApplication@EnableAutoConfiguration@EntityScan("com.yungoal.domain.po")@ComponentScan("com.yungoal")@PropertySource({
"classpath:schedule.properties"})@EnableJpaRepositories(basePackages = "com.yungoal.repository")@EnableScheduling@EnableDubbopublic class BackendApplicationServer { public static void main(String[] args) { SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(BackendApplicationServer.class); springApplicationBuilder.web(WebApplicationType.NONE); springApplicationBuilder.run(args); }}

消费者中调用服务:

@Reference(version = "1.0.0", timeout = 360000)    private ITenantProvider iTenantProvider = null;

Reference属性类完整路径位于:import com.alibaba.dubbo.config.annotation.Reference;

 

转载地址:http://uqdix.baihongyu.com/

你可能感兴趣的文章
WPF:Animation动画-TargetValues目标值From、To、By动画
查看>>
vue进行wepack打包执行npm run build出现错误
查看>>
nginx搭建
查看>>
【d3.js v4基础】过渡transition
查看>>
VUEJS开发规范
查看>>
Android系统的创世之初以及Activity的生命周期
查看>>
彻底解决Linux下memcached的安装
查看>>
人人都会数据采集- Scrapy 爬虫框架入门
查看>>
Android网络编程11之源码解析Retrofit
查看>>
apache .htaccess 文件配置记录
查看>>
我的全站https之路
查看>>
不使用三方包时,如何在社交系统ThinkSNS中建立优雅的用户权限管理【研发日记13】...
查看>>
学会使用npm脚本
查看>>
前端面试之htm5新特性
查看>>
实现atoi函数(string转integer)
查看>>
虚拟机编译安装lnmp(centos7,nginx1.12.0,MariaDB 10.2,php-7.1.6)
查看>>
Java IO学习笔记三
查看>>
JS 原型的解释
查看>>
Yii2中你可能忽略但很有用的两个方法batch&each
查看>>
高程(第二章) 在HTML中使用JavaScript
查看>>