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

做网站一般用什么语言wordpress添加签名

做网站一般用什么语言,wordpress添加签名,做微网站的公司哪家好呢,如何建立微信公众号 免费OpenFeign的使用 openFeign的作用是服务间的远程调用 ,比如通过OpenFeign可以实现调用远程服务。 已经有了LoadBalancer为什么还要用openFeign? 在微服务架构中,LoadBalancer和OpenFeign虽然都提供了服务间调用的能力,但它们的设计目的和…

OpenFeign的使用

openFeign的作用是服务间的远程调用 ,比如通过OpenFeign可以实现调用远程服务。

已经有了LoadBalancer为什么还要用openFeign?

  • 在微服务架构中,LoadBalancer和OpenFeign虽然都提供了服务间调用的能力,但它们的设计目的和使用场景有所不同。
  • LoadBalancer主要关注于服务间的负载均衡,它可以帮助客户端在多个服务实例之间分配请求,以实现高可用性和性能优化。
  • 而OpenFeign则提供了一种声明式的Web服务客户端编程模型,它使得编写服务间调用的代码更加简洁和直观。

OpenFeign到底是什么?

官方文档地址,https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/。

OpenFeign是Spring cloud框架中集成的声明式HTTP客户端工具。

OpenFeign可以让远程调用服务达到像本地调用方法一样的体验。

OpenFeign怎么用?

OpenFeign在服务消费端使用,比如某个服务使用OpenFeign调用其它服务

1.引入依赖,在项目 的pom文件添加:

<!-- openfeign 远程调用 -->
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

2.在项目启动类上添加@EnableFeignClients注解,开启openFeign功能

@EnableFeignClients
@SpringBootApplication
@EnableDiscoveryClient			
public class TlmallOrderApplication {

3.编写OpenFeign客户端,调用其它微服务

@FeignClient(name = "tlmall-storage")
public interface StorageServiceFeignClient {@PostMapping("/storage/reduce-stock")Result<?> reduceStock(@RequestBody StorageDTO productReduceStockDTO);}@FeignClient(name = "tlmall-account")
public interface AccountServiceFeignClient {@PostMapping("/account/reduce-balance")Result<?> reduceBalance(@RequestBody AccountDTO accountReduceBalanceDTO);}

4.服务发起调用 ,像调用本地方式一样调用其它服务

@Autowiredprivate AccountServiceFeignClient accountService;@Autowiredprivate StorageServiceFeignClient storageService;public Result<?> createOrder(String userId, String commodityCode, Integer count) {// deduct storageStorageDTO storageDTO = new StorageDTO();storageDTO.setCommodityCode(commodityCode);storageDTO.setCount(count);//RestTemplate远程调用//String storage_url = "http://localhost:8010/storage/reduce-stock";//整合了Nacos+LoadBalaner,可以使用微服务名tlmall-storage代替localhost:8020//String storage_url = "http://tlmall-storage/storage/reduce-stock";//Integer storageCode = restTemplate.postForObject(storage_url,storageDTO, Result.class).getCode();//openFeign远程调用Integer storageCode = storageService.reduceStock(storageDTO).getCode();if (storageCode.equals(COMMON_FAILED.getCode())) {throw new BusinessException("stock not enough");}// deduct balanceint price = count * 2;AccountDTO accountDTO = new AccountDTO();accountDTO.setUserId(userId);accountDTO.setPrice(price);//RestTemplate远程调用//String account_url = "http://localhost:8020/account/reduce-balance";//整合了Nacos+LoadBalaner,可以使用微服务名tlmall-account代替localhost:8020//String account_url = "http://tlmall-account/account/reduce-balance";//Integer accountCode = restTemplate.postForObject(account_url, accountDTO, Result.class).getCode();//openFeign远程调用Integer accountCode = accountService.reduceBalance(accountDTO).getCode();if (accountCode.equals(COMMON_FAILED.getCode())) {throw new BusinessException("balance not enough");}
}

重启服务,验证

1.到Nacos控制台查看服务是否注册成功
2.进行测试访问url
3.借助idea工具,复制一个服务,再次操作,看当有2个服务时,能否把2个都调用了

http://www.yayakq.cn/news/674631/

相关文章:

  • 昆山网站建设义搏哪家公司做跳转网站
  • 建网站多少钱一个平台视频格式转换网页版
  • 广药网站建设试卷义乌网站建设郭
  • 怎样做网站框架图2016网站优化
  • 淄博桓台学校网站建设方案做网批那个网站好
  • 公司免费推广网站阳江网红打卡景点
  • 在中国做国外网站微信后台网站建设
  • 万户网络网站顾问北京seo招聘信息
  • 学校网站建设关键技术个人网站建设价格套餐
  • 网站标签title个人站长网站需要注册公司吗
  • 网站做百度百科的好处做商城网站可以个人备案
  • 关于实施公司网站建设的请示邢台招聘信息最新招聘2023
  • 常平东站是东莞东站吗杭州科技学校网站建设
  • 网站建设项目体会wordpress如何设置头像
  • 如何给公司做网站wordpress主题布局
  • 网站上怎么做图片变换动图免费s站推广网站
  • 网站收录查询方法seo深度优化公司
  • 网站移动排名百度上怎么打广告宣传
  • 怎样自创广告网站中国摄影官方网站
  • 企业品牌网站源码永久免费erp
  • 钦州网站建设公司用struts2框架做的网站
  • 网站seo优化有哪些淮安 网站建设
  • 企业官网响应式网站域名防红直连
  • 陇南市建设局官方网站网站建设学多长时间
  • 安徽省建设厅门户网站深圳企业所得税怎么征收
  • 做育儿类网站用什么程序好商丘企业网站服务
  • 优化网站 主题dw网页制作图片
  • 有没有工程外包的网站企业解决方案能力介绍
  • 济南食品行业网站开发中国能源建设集团有限公司是什么级别
  • 数字营销1+x网站佛山贸易网站建设