Spring Cloud Alibaba 初体验(三) Nacos 与 Dubbo 集成
一、新建项目
新建项目,只放置接口,用于暴露 Dubbo 服务接口
public interface GreetingService {
String greeting();
}
二、provider
本文以上文中的 Service1 作为 provider,以 Service2 作为 consumer
2.1 添加依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
2.2 实现接口
@Service
@Component
public class GreetingServiceImpl implements GreetingService {
@Value("${server.port:0}")
private Integer port;
@Override
public String greeting() {
return "hello from port: " + port;
}
}
@Service 为 org.apache.dubbo.config.annotation.Service (旧的版本为 com.alibaba.dubbo.config.annotation.Service),此处的 @Service 只能供 Dubbo RPC 调用,如果需要像之前一样正常在 Controller 层调用需要再添加 @Component 注解 (或者直接不添加 @Component 在项目内也通过 Dubbo 调用)
2.3 新增配置
dubbo:
scan:
base-packages: com.karonda.service1.service.impl
protocol:
name: dubbo
port: -1 # -1 表示端口自增
registry:
address: nacos://192.168.92.1:8848
三、consumer
3.1 调用服务
@Reference
private GreetingService greetingService;
@RequestMapping("/dubboGreeting")
public String dubboGreeting() {
return greetingService.greeting();
}
@Reference 为 org.apache.dubbo.config.annotation.Reference (旧的版本为 com.alibaba.dubbo.config.annotation.Reference)
3.2 新增配置
dubbo:
protocol:
name: dubbo
port: -1
registry:
address: nacos://192.168.92.1:8848
consumer:
check: false # 不加此配置项目启动时可能会失败
启动服务,访问 http://localhost:8079/dubboGreeting 可以看到结果
Spring Cloud Alibaba 初体验(三) Nacos 与 Dubbo 集成的更多相关文章
- Spring Cloud Alibaba 初体验(一) Nacos 配置中心
一.Nacos 下载与初始化配置 本文使用1.2.0,下载地址:https://github.com/alibaba/nacos/releases Nacos 单机模式支持持久化配置到 MySQL 数 ...
- Spring Cloud Alibaba 初体验(二) Nacos 服务注册与发现 + 集成 Spring Cloud Gateway
一.服务注册 添加依赖: <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>s ...
- Spring Cloud Alibaba 初体验(六) Seata 及结合 MyBatis 与 MyBatis-Plus 的使用
一.下载与运行 本文使用 Seata 1.1.0:https://github.com/seata/seata/releases Windows 环境下双击 bin/seata-server.bat ...
- Spring Cloud Alibaba 初体验(四) Sentinel
一.Sentinel 下载与运行 本文使用 Sentinel 1.7.1:https://github.com/alibaba/Sentinel/releases 使用自定义端口 8089 运行 Se ...
- Spring Cloud Alibaba 初体验(五) SkyWalking
一.下载与运行 本文使用 SkyWalking 7.0.0:https://www.apache.org/dyn/closer.cgi/skywalking/7.0.0/apache-skywalki ...
- Spring Cloud Alibaba基础教程:Nacos配置的多环境管理
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
- Spring Cloud Alibaba基础教程:Nacos的集群部署
继续说说生产环境的Nacos搭建,通过上一篇<Spring Cloud Alibaba基础教程:Nacos的数据持久化>的介绍,我们已经知道Nacos对配置信息的存储原理,在集群搭建的时候 ...
- Spring Cloud Alibaba基础教程:Nacos的数据持久化
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
- Spring Cloud Alibaba基础教程:Nacos配置的多文件加载与共享配置
前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...
随机推荐
- Antisymmetry
题意描述 Antisymmetry 求给定的字符串的子串集合中为"反对串"的个数. 反对串的定义为,将这个字符串 \(0\) 和 \(1\) 取反后,再将整个串反过来和原串一样,就 ...
- JNI-Thread中start方法的调用与run方法的回调分析
前言 在java编程中,线程Thread是我们经常使用的类.那么创建一个Thread的本质究竟是什么,本文就此问题作一个探索. 内容主要分为以下几个部分 1.JNI机制的使用 2.Thread创建线程 ...
- SQL Server中约束的介绍
SQL Server中约束的介绍(转载收藏) Posted on 2010-09-03 11:05 grayboy 阅读(8501) 评论(0) 编辑 收藏 作者:GrayBoy 出处:http:// ...
- leetcode 43:construct-binary-tree-from-inorder
题目描述 给出一棵树的中序遍历和后序遍历,请构造这颗二叉树 注意: 保证给出的树中不存在重复的节点 Given inorder and postorder traversal of a tree, c ...
- 我叫Mongo,干了「查询终结篇」,值得您拥有
这是mongo第三篇"查终结篇",后续会连续更新5篇 mongodb的文章总结上会有一系列的文章,顺序是先学会怎么用,在学会怎么用好,戒急戒躁,循序渐进,跟着我一起来探索交流. 通 ...
- kubernetes-1.18.2集群安装-02
一.基础配置 修改主机名 # 在 172.17.32.23 上:hostnamectl set-hostname k8s-master01bash# 在 172.17.32.38 上:hostnam ...
- 当Prometheus遇到混沌工程
一.背景 最近容器组在开发云平台的监控.报警功能. 大致的实现策略是: 1.云平台页面上配置告警规则 2.Prometheus完成监控数据的聚合 3.当Prometheus聚合后的监控数据满足告警规则 ...
- go常见问题
1.至少知道go的fiber概念,调度原理,M/P/G的角色分工: 2.map的数据结构,get/put/delete过程,扩容机制: 3.slice的内存结构,扩容机制,巨型slice产生的垃圾回收 ...
- 剑指offer刷题(算法类_1)
斐波那契数列 007-斐波拉契数列 题目描述 题解 代码 复杂度 008-跳台阶 题目描述 题解 代码 复杂度 009-变态跳台阶 题目描述 题解 代码 复杂度 010-矩形覆盖 题目描述 题解 代码 ...
- 微信_跳一跳辅助程序_Python_(带GitHub项目地址)
1.安装Python(推荐3.6) https://www.python.org/downloads/ 2.在github上下载脚本 [github项目地址](https://github.com/w ...