订单系统-RPC快速入门

RPC快速入门

概述

关于rpc,只需要知道他是一种协议,项目之间能够远程调用函数。

快速入门

我们前边下载好的两个包,在idea中打开之后,我们创建这么几个文件夹。
![[Pasted image 20240326095149.png]]

![[Pasted image 20240326095240.png]]

至于是干什么的,以后细说。创建好之后我们在product-client子包中创建RemoteProductService接口:

package com.example.product.feign;import com.example.product.feign.common.CommonResult;
import com.example.product.feign.entity.Price;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;import java.util.List;@FeignClient(value = "product-service")
public interface RemoteProductService {@GetMapping("/hello")String hello();}

然后再product-service的controller中创建HelloController类并实现接口RemoteProductService:

package com.example.product.controller;import com.example.product.feign.common.CommonResult;
import com.example.product.feign.entity.Price;
import com.example.product.feign.RemoteProductService;
import com.example.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController
public class ProductController implements RemoteProductService {@Autowiredprivate ProductService productService;@GetMapping("/hello")@Overridepublic String hello() {return "hello world";}}

完成之后,需要打开product的pom.xml文件,将下面几行注释掉,然后install,完成之后打开注释再次install。
![[Pasted image 20240326095803.png]]
接下来就是对order的操作,我们需要再order的pom.xml文件中导入

<dependency><groupId>com.example</groupId><artifactId>product-client</artifactId><version>0.0.1-SNAPSHOT</version>
</dependency>

这个就是我们刚刚打包的jar包,然后在order-service中导入依赖,等待依赖导入完成。完成之后在controller下创建一个controller进行测试:

<dependency><groupId>com.example</groupId><artifactId>product-client</artifactId>
</dependency>
package com.example.order.controller;import com.example.order.param.OrderParam;
import com.example.order.service.OrderService;
import com.example.order.vo.OrderResultVO;
import com.example.product.feign.RemoteProductService;
import com.example.product.feign.common.CommonResult;
import com.example.product.feign.entity.Price;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import java.util.List;@RestController
@Slf4j
public class OrderController {@Resourceprivate RemoteProductService remoteProductService;@GetMapping("/test")public String test(){log.info(remoteProductService.toString());return remoteProductService.hello();}}

然后我们启动项目使用ApiPost软件进行接口的测试,记得启动本地的nacos。
我们先测试product的端口(9094):
![[Pasted image 20240326100403.png]]

然后呢测试order的端口(9093):
![[Pasted image 20240326100439.png]]

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/570520.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Google AI 肺癌筛查的计算机辅助诊断

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

中小型集群部署,Docker Swarm(集群)使用及部署应用介绍

1、Docker Swarm简介 说到集群&#xff0c;第一个想到的就是k8s&#xff0c;但docker官方也提供了集群和编排解决方案&#xff0c;它允许你将多个 Docker 主机连接在一起&#xff0c;形成一个“群集”&#xff08;Swarm&#xff09;&#xff0c;并可以在这个 Swarm 上运行和管…

OC 技术 苹果内购

一直觉得自己写的不是技术&#xff0c;而是情怀&#xff0c;一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的&#xff0c;希望我的这条路能让你们少走弯路&#xff0c;希望我能帮你们抹去知识的蒙尘&#xff0c;希望我能帮你们理清知识的脉络&#xff0…

对谈Concured首席技术官:利用AI和MongoDB打造个性化内容推荐系统

Built with MongoDB 栏目采访了AI初创企业Concured在成立约一年后加入的首席技术官 Tom Wilson&#xff0c;围绕 Concured 的人工智能使用情况、Wilson 加入团队的过程、坚持选择MongoDB的原因以及公司未来发展展开讨论。 关于Concured 内容无处不在。无论消费者寻找什么或所处…

【MATLAB源码-第16期】基于matlab的MSK定是同步仿真,采用gardner算法和锁相环。

操作环境&#xff1a; MATLAB 2022a 1、算法描述 **锁相环&#xff08;PLL&#xff09;** 是一种控制系统&#xff0c;用于将一个参考信号的相位与一个输入信号的相位同步。它在许多领域中都有应用&#xff0c;如通信、无线电、音频、视频和计算机系统。锁相环通常由以下几个…

【Java】LinkedList vs. ArrayList:Java中的数据结构选择

人不走空 &#x1f308;个人主页&#xff1a;人不走空 &#x1f496;系列专栏&#xff1a;算法专题 ⏰诗词歌赋&#xff1a;斯是陋室&#xff0c;惟吾德馨 目录 &#x1f308;个人主页&#xff1a;人不走空 &#x1f496;系列专栏&#xff1a;算法专题 ⏰诗词歌…

图像处理与视觉感知---期末复习重点(4)

文章目录 一、图像复原与图像增强1.1 概述1.2 异同点 二、图像复原/退化模型2.1 模型图简介2.2 线性复原法 三、彩色基础四、彩色模型五、彩色图像处理 一、图像复原与图像增强 1.1 概述 1. 图像增强技术一般要利用人的视觉系统特性&#xff0c;目的是取得较好的视觉效果&…

《仙剑7》登陆Xbox主机平台年末大作空窗期

首发一年后&#xff0c;《仙剑奇侠传7》终于登陆Xbox主机平台&#xff0c;而这也恰逢Xbox平台年末大作的窗口期。 随着年底大作的稀缺&#xff0c;以及海外3A RPG《星空》的延期&#xff0c;2022年底的这段时间给Xbox玩家体验《刀剑7》留下了一段空白。 可以说是因祸得福。 《仙…

Web CSS笔记2

目录 1、背景 ①、背景图片(image) ②、背景平铺&#xff08;repeat&#xff09; ③、背景位置(position) ④、背景附着&#xff08;attachment&#xff09; ⑤、背景透明(CSS3) ⑥、背景图片缩放大小&#xff08;size&#xff09;&#xff1a; ⑦、背景简写 2、标签显…

并发编程之的ArrayList安全性的详细解析

ArrayList不安全 ArrayList中的add方法没有synchronized修饰&#xff0c;是不安全的 下面代码运行结果&#xff08;异常 java.util.ConcurrentModificationException&#xff09;&#xff1a; ​import java.util.ArrayList; import java.util.List; import java.util.UUID; ​…

[CISCN2019 华东北赛区]Web2

[CISCN2019 华东北赛区]Web2 随便注册一个登录&#xff0c;发现 还有反馈页面&#xff0c;一看就知道大概率是xss&#xff0c;应该是为了得到管理员cookie扫描了一下&#xff0c;果然有admin.php后台登录 buu可以连接访问外网了&#xff0c;所以内部的xss平台关闭了&#xff0…

elasticsearch _cat/indices docs.count is different than <index>/_count

今天遇到一个问题&#xff0c;kibana中看到文档数与下面语句查询到的不同 GET /_cat/count/jiankunking_xxxxx_product_expand_test?v GET /jiankunking_xxxxx_product_expand_test/_search?track_total_hitstrue语句查询结果 epoch timestamp count 1711433785 06:16…