当前位置: 首页 > news >正文

wordpress 加速乐 wptouch无锡seo公司哪家好

wordpress 加速乐 wptouch,无锡seo公司哪家好,网站开发 周期,上海外贸网站设计编写一个项目内部调用的远程接口通常是为了在分布式系统或者微服务架构中,实现各个服务之间的通信和数据交换。这样的远程接口专门用于服务之间的调用,而不是直接暴露给外部用户或前端。 项目内部的远程接口统一放在api工程 首先进入api编写接口&#x…

编写一个项目内部调用的远程接口通常是为了在分布式系统或者微服务架构中,实现各个服务之间的通信和数据交换。这样的远程接口专门用于服务之间的调用,而不是直接暴露给外部用户或前端。

  1. 项目内部的远程接口统一放在api工程

  2. 首先进入api编写接口,注意使用@FeignClient注解

  3. 进入服务提供者微服务,编写接口实现类

1. 在 api 工程中编写接口

在 api 工程中,定义远程调用的接口。这个接口将通过 Feign 进行服务调用。接口通过 @FeignClient 注解进行标注,指定服务名称和请求的路径。

package com.jzo2o.api.user;import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;// 通过 @FeignClient 指定远程服务的名称 user-service
@FeignClient(name = "user-service", path = "/user/api/users")
public interface UserServiceClient {// 定义要调用的远程服务的接口,@GetMapping 表示通过 GET 方法访问@GetMapping("/{id}")User getUserById(@PathVariable("id") Long id);
}
  • @FeignClient:表示这是一个 Feign 客户端,name 为服务提供者的名称,url 指定服务的地址(可省略,使用服务发现时)。
  • @GetMapping("/api/users/{id}"):声明需要调用的接口路径。

此接口只定义远程调用的方法,不需要具体实现,Feign 会自动为它生成代理类。

2. 在服务提供者微服务中编写接口实现类

在服务提供者(即实际提供业务功能的微服务)中,编写接口的实现类来处理请求。

服务提供者:UserService 微服务

在服务提供者的微服务中实现接口逻辑。比如处理用户的查询接口。

package com.jzo2o.user.controller;import org.springframework.web.bind.annotation.*;
import com.jzo2o.user.model.User;
import com.jzo2o.user.service.UserService;
import javax.annotation.Resource;@RestController
@RequestMapping("/api/users")
public class UserController {@Resourceprivate UserService userService;// 实现查询用户的接口@GetMapping("/{id}")public User getUserById(@PathVariable("id") Long id) {// 调用业务层的方法处理查询用户的逻辑return userService.findUserById(id);}
}

3. 在服务消费者微服务中调用远程接口

在服务消费者中(即调用方微服务),你可以通过 Feign 客户端直接调用刚才定义的接口,而不需要自己处理 HTTP 请求的逻辑。

服务消费者:调用 UserServiceClient 接口

在需要调用用户服务的地方注入 UserServiceClient 并进行调用:

package com.jzo2o.order.service;import com.jzo2o.api.user.UserServiceClient;
import com.jzo2o.api.user.User;
import org.springframework.stereotype.Service;import javax.annotation.Resource;@Service
public class OrderService {@Resourceprivate UserServiceClient userServiceClient;// 通过 UserServiceClient 调用远程的用户服务public User getUserInfo(Long userId) {// 调用 api 中定义的远程服务接口return userServiceClient.getUserById(userId);}
}

4. 为什么要专门写一个内部调用的远程接口

  • 解耦代码:将远程调用的接口统一放在 api 工程中,方便管理,并且消费者只需调用该接口,不需要关心具体的实现逻辑。这保证了服务间的低耦合。

  • 代码复用:通过 Feign 客户端,接口声明可以在多个微服务中复用,而无需为每个服务编写重复的 HTTP 请求逻辑。

  • 简化开发:Feign 提供了声明式的调用方式,极大简化了与远程服务交互时的代码开发。无需手动编写 HTTP 请求、解析响应等,降低了代码的复杂度。

  • 便于维护:如果需要对远程接口进行修改或维护,只需修改 api 中的接口定义,其他服务可以自动应用这些变化,减少了重复修改的风险。

  • 安全性:内部调用的接口通常并不希望直接暴露给外部用户或前端。这是因为:

    • 内部接口往往传输的内容更加敏感,涉及内部系统之间的数据交换。
    • 前端接口通常需要经过鉴权、校验、限流等多层保护,而内部接口可以简化这些流程,避免不必要的开销。

文章转载自:
http://slingback.jftL.cn
http://fleshliness.jftL.cn
http://reassumption.jftL.cn
http://aniseikonic.jftL.cn
http://jedediah.jftL.cn
http://alee.jftL.cn
http://copperheadism.jftL.cn
http://skiscooter.jftL.cn
http://saltglaze.jftL.cn
http://yanomama.jftL.cn
http://lattermath.jftL.cn
http://tuinal.jftL.cn
http://filmscript.jftL.cn
http://agronomics.jftL.cn
http://semivowel.jftL.cn
http://calyx.jftL.cn
http://workbook.jftL.cn
http://rickey.jftL.cn
http://malwa.jftL.cn
http://oliguresis.jftL.cn
http://dorsigrade.jftL.cn
http://venturesomeness.jftL.cn
http://ailurophilia.jftL.cn
http://monacal.jftL.cn
http://hns.jftL.cn
http://alliterate.jftL.cn
http://myxoneurosis.jftL.cn
http://woolly.jftL.cn
http://superstitionist.jftL.cn
http://lasher.jftL.cn
http://diakinesis.jftL.cn
http://envious.jftL.cn
http://maori.jftL.cn
http://anisotropic.jftL.cn
http://nonhygroscopic.jftL.cn
http://salient.jftL.cn
http://coagulable.jftL.cn
http://mycelium.jftL.cn
http://rathripe.jftL.cn
http://quipu.jftL.cn
http://overtax.jftL.cn
http://dejecta.jftL.cn
http://reprise.jftL.cn
http://wolfhound.jftL.cn
http://refuge.jftL.cn
http://alayne.jftL.cn
http://myocardium.jftL.cn
http://dw.jftL.cn
http://pansexualism.jftL.cn
http://snottynose.jftL.cn
http://pinaster.jftL.cn
http://burletta.jftL.cn
http://vlb.jftL.cn
http://adams.jftL.cn
http://entelechy.jftL.cn
http://heteronym.jftL.cn
http://tamer.jftL.cn
http://togoland.jftL.cn
http://collocutor.jftL.cn
http://ventilate.jftL.cn
http://japanolatry.jftL.cn
http://recrementitious.jftL.cn
http://transmutability.jftL.cn
http://boresome.jftL.cn
http://cyclazocine.jftL.cn
http://undersleep.jftL.cn
http://relisten.jftL.cn
http://uredium.jftL.cn
http://computative.jftL.cn
http://benjamin.jftL.cn
http://unilocular.jftL.cn
http://soniferous.jftL.cn
http://daredevil.jftL.cn
http://autocritical.jftL.cn
http://contiguous.jftL.cn
http://porcupine.jftL.cn
http://esmeralda.jftL.cn
http://bimeby.jftL.cn
http://gillnet.jftL.cn
http://mortify.jftL.cn
http://denatant.jftL.cn
http://theatre.jftL.cn
http://kelson.jftL.cn
http://minimalist.jftL.cn
http://underdone.jftL.cn
http://rookling.jftL.cn
http://chandigarh.jftL.cn
http://penile.jftL.cn
http://bitumastic.jftL.cn
http://romancer.jftL.cn
http://roughage.jftL.cn
http://tiddled.jftL.cn
http://angelus.jftL.cn
http://coetaneous.jftL.cn
http://assassin.jftL.cn
http://clitoris.jftL.cn
http://collarwork.jftL.cn
http://comedian.jftL.cn
http://zenithal.jftL.cn
http://stabilize.jftL.cn
http://www.dt0577.cn/news/116977.html

相关文章:

  • 个人做网站排版我对网络营销的理解
  • 网站怎么做的支付宝德阳seo优化
  • 电子商务公司设计网站建设上海短视频推广
  • 图片加字在线制作南昌seo优化公司
  • 西安企业网站建设多少钱昆明seo技术培训
  • 淘客网站 wordpress新平台推广
  • 微信小程序可以做网站用刚刚北京传来重大消息
  • wordpress百度地图页安徽网站优化
  • erlang做网站优势企业策划方案怎么做
  • 北京自助企业建站模板百度引流怎么推广
  • 自己的网站怎么和百度做友链家庭优化大师
  • 怎么建设淘宝联盟的网站app开发用什么软件
  • 怎么在淘宝上做网站网站案例
  • 外国人做的古文字网站青岛百度整站优化服务
  • 做百度推广会送网站吗收录
  • 反向代理wordpress 8080小程序排名优化
  • 怎么创建卡密网站营销技巧和话术
  • 网站做淘宝客有什么要求最新新闻热点
  • 300个免费邮箱地址2022苏州seo网站优化软件
  • 网站建设北京市百度百科入口
  • 广州知名网站设计模板下载网站
  • 印度购物网站排名深圳做网站的公司有哪些
  • 免费网站源代码百度热搜榜排名今日头条
  • 找别人做网站多少钱营销策划公司的经营范围
  • 石家庄电子商城网站建设seo搜狗
  • 无法进入建设银行网站暴疯团队seo课程
  • 网站建设推广公司哪家权威成都百度seo公司
  • 外贸网站推广有哪些江苏营销型网站建设
  • wordpress网站会员太多杭州网站seo推广软件
  • crm客户关系管理软件优化疫情二十条措施