在使用Ribbon调用广告投放系统API之前,我们需要先创建2个VO对象,AdPlanVO,AdPlanGetRequestVO.

//数据请求对象
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdPlanGetRequestVO {
private Long userId;
private List<Long> planIds;
} ---------------------------------- //API请求响应结果反序列化对象
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AdPlanVO {
private Long planId;
private Long userId;
private String planName;
private Integer planStatus;
private Date startDate;
private Date endDate;
private Date createTime;
private Date updateTime;
}

AdSearchApplication启动类中,添加RestTemplate客户端。

public class AdSearchApplication {
...
/**
* 注册{@link RestTemplate}Bean
* @return
*/
@Bean
@LoadBalanced //让RestTemplate在调用服务的时候,可以实现负载均衡
RestTemplate restTemplate(){
return new RestTemplate();
}
}

创建一个controller,来测试调用广告提供系统的API

/**
* SearchController for search information controller
*
* @author <a href="mailto:magicianisaac@gmail.com">Isaac.Zhang | 若初</a>
*/
@RestController
@Slf4j
@RequestMapping(path = "/search")
public class SearchController {
//注入RestTemplate
private final RestTemplate restTemplate;
@Autowired
public SearchController(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
} @GetMapping(path = "/plan/get-ribbon")
public CommonResponse<List<AdPlanVO>> getAdPlansUseRibbon(@RequestBody AdPlanGetRequestVO requestVO) {
log.info("ad-search::getAdPlansUseRibbon -> {}", JSON.toJSONString(requestVO));
return restTemplate.postForEntity(
"http://mscx-ad-sponsor/ad-sponsor/plan/get", requestVO, CommonResponse.class
).getBody();
} @GetMapping(path = "/user/get")
public CommonResponse getUsers(@Param(value = "username") String username) {
log.info("ad-search::getUsers -> {}", JSON.toJSONString(username));
CommonResponse commonResponse = restTemplate.getForObject(
"http://mscx-ad-sponsor/ad-sponsor/user/get?username={username}", CommonResponse.class, username
);
return commonResponse;
}
}

[Spring cloud 一步步实现广告系统] 10. 使用Ribbon 实现微服务调用的更多相关文章

  1. [Spring cloud 一步步实现广告系统] 11. 使用Feign实现微服务调用

    上一节我们使用了Ribbon(基于Http/Tcp)进行微服务的调用,Ribbon的调用比较简单,通过Ribbon组件对请求的服务进行拦截,通过Eureka Server 获取到服务实例的IP:Por ...

  2. [Spring cloud 一步步实现广告系统] 21. 系统错误汇总

    广告系统学习过程中问题答疑 博客园 Eureka集群启动报错 Answer 因为Eureka在集群启动过程中,会连接集群中其他的机器进行数据同步,在这个过程中,如果别的服务还没有启动完成,就会出现Co ...

  3. [Spring cloud 一步步实现广告系统] 22. 广告系统回顾总结

    到目前为止,我们整个初级广告检索系统就初步开发完成了,我们来整体回顾一下我们的广告系统. 整个广告系统编码结构如下: mscx-ad 父模块 主要是为了方便我们项目的统一管理 mscx-ad-db 这 ...

  4. [Spring cloud 一步步实现广告系统] 19. 监控Hystrix Dashboard

    在之前的18次文章中,我们实现了广告系统的广告投放,广告检索业务功能,中间使用到了 服务发现Eureka,服务调用Feign,网关路由Zuul以及错误熔断Hystrix等Spring Cloud组件. ...

  5. [Spring cloud 一步步实现广告系统] 2. 配置&Eureka服务

    父项目管理 首先,我们在创建投放系统之前,先看一下我们的工程结构: mscx-ad-sponsor就是我们的广告投放系统.如上结构,我们需要首先创建一个Parent Project mscx-ad 来 ...

  6. [Spring cloud 一步步实现广告系统] 7. 中期总结回顾

    在前面的过程中,我们创建了4个project: 服务发现 我们使用Eureka 作为服务发现组件,学习了Eureka Server,Eureka Client的使用. Eureka Server 加依 ...

  7. [Spring cloud 一步步实现广告系统] 6. Service实现&Zuul配置&Test

    DAO层设计实现 这里我们使用Spring DATA JPA来实现数据库操作,当然大家也可以使用Mybatis,都是一样的,我们依然以用户表操作为例: /** * AdUserRepository f ...

  8. [Spring cloud 一步步实现广告系统] 1. 业务架构分析

    什么是广告系统? 主要包含: 广告主投放广告的<广告投放系统> 媒体方(广告展示媒介-)检索广告用的<广告检索系统> 广告计费系统(按次,曝光量等等) 报表系统 Etc. 使用 ...

  9. [Spring cloud 一步步实现广告系统] 20. 系统运行测试

    系统运行 经过长时间的编码实现,我们的主体模块已经大致完成,因为之前我们都是零散的对各个微服务自行测试,接下来,我们需要将所有的服务模块进行联调测试,Let's do it. 清除测试数据&测 ...

随机推荐

  1. NodeJS4-9静态资源服务器实战_发到npm上

    登录->publish一下 ->上npm官网查看 -> 安装全局 //登录 npm login //推上去npm npm publish //全局安装 npm i -g 你的文件名

  2. java8-详解Lamda表达式

    一回顾与说明     通过之前发布的"Java8Lamda和Stream原理引入"一文章中你已经了解了为什么会有Lamda表达式的由来,Lamda表达式的基本语法等:Lamda表达 ...

  3. jdk13-新特性预览

    一新特性 350: Dynamic CDS Archives(动态CDS档案) 351: ZGC: Uncommit Unused Memory(ZGC:取消提交未使用的内存) 353: Reimpl ...

  4. python的memory_profiler模块使用

    本文主要介绍了python内存分析工具: memory_profiler,可以展示每一行代码执行所增加的内存,方便做内存调优和排除bug memory_profiler是第三方模块,需要安装才能使用 ...

  5. 基于windows server 2016和sqlserver 2016 AlwaysOn的群集配置

    文档:基于windows server 2016和sqlserver 2...链接:http://note.youdao.com/noteshare?id=4f07c1c3f7d0e32b7631d7 ...

  6. ElasticSearch 时间格式

    "datetime": { "type": "date", "format": "yyyy-MM-dd HH: ...

  7. 【译】ModSecurity事务生命周期

    本篇简要介绍ModSecurity Transaction Lifecycle,也即ModSecurity的事务生命周期. Transaction Lifecycle In ModSecurity, ...

  8. Cesium 本地部署案例

    众所周知,cesium的服务器是搭建在国外的,所以我们国内的用户访问的时候贼慢.有时想查个api或者看个案例半天都进不去,今天我来说一下傻瓜式搭建本地的cesium环境,用于大家没事查资料用!步骤:1 ...

  9. 63-容器在 Weave 中如何通信和隔离?

    上一节我们分析了 Weave 的网络结构,今天讨论 Weave 的连通和隔离特性. 首先在host2 执行如下命令: weave launch 192.168.0.44 这里必须指定 host1 的 ...

  10. javascript数组拆分为三个一组

    首先构建原始数据. var arr = [ {name:'yanggb1',age:'15'}, {name:'yanggb2',age:'16'}, {name:'yanggb3',age:'17' ...