spring cloud microservice provider and consumer
MicroService Provider:https://files.cnblogs.com/files/xiandedanteng/empCloud190824.rar
MicroService Consumer:https://files.cnblogs.com/files/xiandedanteng/empCloudConsumer190824.rar
After started comsumer. If I type "http://localhost:8000/emp/2" in browser, I will get:
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Sat Aug 24 14:54:38 CST 2019 There was an unexpected error (type=Internal Server Error, status=500). I/O error on GET request for "http://localhost:8080/emp/2": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
And then started provider, try "http://localhost:8000/emp/2" again, I can get:
<Emp> <id>2</id> <name>刘德华</name> <age>42</age> </Emp>
Oberviously, comsumer at port 8000 got the information given by provider at port 8088.
the essential code in consumer is:
package com.hy.empcloud;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class EmpControl {
@Autowired
EmpService service;
@Autowired
RestTemplate restTemplate;
@GetMapping("/test")
public String test() {
return "Hello";
}
@GetMapping("/emp/{id}")
public Emp get(@PathVariable Long id) throws Exception{
return this.restTemplate.getForObject("http://localhost:8080/emp/"+id, Emp.class);
}
@GetMapping("/all")
public List<Emp> get() {
return this.service.getAll();
}
}
the key code of provider is:
package com.hy.empcloud;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
@RestController
public class EmpControl {
@Autowired
EmpService service;
@Autowired
RestTemplate restTemplate;
@GetMapping("/test")
public String test() {
return "Hello";
}
@GetMapping("/emp/{id}")
public Emp get(@PathVariable Long id) throws Exception{
return this.service.find(id);
}
@GetMapping("/all")
public List<Emp> get() {
return this.service.getAll();
}
}
--END--
2019年8月24日15点02分
spring cloud microservice provider and consumer的更多相关文章
- 微服务架构的服务与发现-Spring Cloud
1 为什么需要服务发现 简单来说,服务化的核心就是将传统的一站式应用根据业务拆分成一个一个的服务,而微服务在这个基础上要更彻底地去耦合(不再共享DB.KV,去掉重量级ESB),并且强调DevOps和快 ...
- Spring Cloud(一):服务治理技术概览【Finchley 版】
Spring Cloud(一):服务治理技术概览[Finchley 版] 发表于 2018-04-14 | 更新于 2018-05-07 | Spring Cloud Netflix 是 Spr ...
- 十分钟了解 spring cloud
1 为什么需要服务发现 简单来说,服务化的核心就是将传统的一站式应用根据业务拆分成一个一个的服务,而微服务在这个基础上要更彻底地去耦合(不再共享DB.KV,去掉重量级ESB),并且强调DevOps和快 ...
- Spring Cloud Alibaba - Spring Cloud Stream 整合 RocketMQ
Spring Cloud Stream 简介 在微服务的开发过程中,可能会经常用到消息中间件,通过消息中间件在服务与服务之间传递消息,不管你使用的是哪款消息中间件,比如RabbitMQ.Kafka和R ...
- Spring Cloud Stream消费失败后的处理策略(四):重新入队(RabbitMQ)
应用场景 之前我们已经通过<Spring Cloud Stream消费失败后的处理策略(一):自动重试>一文介绍了Spring Cloud Stream默认的消息重试功能.本文将介绍Rab ...
- Spring Cloud Stream消费失败后的处理策略(三):使用DLQ队列(RabbitMQ)
应用场景 前两天我们已经介绍了两种Spring Cloud Stream对消息失败的处理策略: 自动重试:对于一些因环境原因(如:网络抖动等不稳定因素)引发的问题可以起到比较好的作用,提高消息处理的成 ...
- Spring Cloud Stream消费失败后的处理策略(二):自定义错误处理逻辑
应用场景 上一篇<Spring Cloud Stream消费失败后的处理策略(一):自动重试>介绍了默认就会生效的消息重试功能.对于一些因环境原因.网络抖动等不稳定因素引发的问题可以起到比 ...
- Spring Cloud Stream消费失败后的处理策略(一):自动重试
之前写了几篇关于Spring Cloud Stream使用中的常见问题,比如: 如何处理消息重复消费 如何消费自己生产的消息 下面几天就集中来详细聊聊,当消息消费失败之后该如何处理的几种方式.不过不论 ...
- spring cloud 学习(6) - zuul 微服务网关
微服务架构体系中,通常一个业务系统会有很多的微服务,比如:OrderService.ProductService.UserService...,为了让调用更简单,一般会在这些服务前端再封装一层,类似下 ...
随机推荐
- ECharts模拟百度迁徙实例
本实例原始信息: 作者:anix 演示地址:Echarts模拟迁徙 源码地址:GitHub-ananix-qianxi 前言 "百度地图春节人口迁徙大数据"(简称"百度迁 ...
- angular使用@angular/material 出现"export 'ɵɵinject' was not found in '@angular/core'
WARNING in ./node_modules/@angular/cdk/esm5/a11y.es5.js 2324:206-214 "export 'ɵɵinject' was not ...
- TensorFlow入门——hello
上一节说了TensorFlow的安装,这一节说一下测试的问题 新建一个Python文件,输入 import tensorflow as tf hello = tf .constant (’Hello, ...
- vue + mixin混入对象使用
vue提供的混入对象mixin,类似于一个公共的组件,其他任何组件都可以使用它.我更经常的是把它当成一个公共方法来使用 在项目中有些多次使用的data数据,method方法,或者自定义的vue指令都可 ...
- service与pod关联
当我们创建pod时,仅仅是创建了pod,要为其创建rc(ReplicationController),他才会有固定的副本,然后为其创建service,集群内部才能访问该pod,使用 NodePort ...
- Python基础:元组
元组(tuple)特点: 1.元组是以圆括号“()”包围的数据集合,不同成员以“,”分隔.通过下标进行访问 2.不可变序列,可以看做不可变的列表,与列表不同:元组中数据一旦确立就不能改变(所以没有类似 ...
- VCL界面开发必备装备!DevExpress VCL v19.1.5你值得拥有
DevExpress VCL Controls是 Devexpress公司旗下最老牌的用户界面套包.所包含的控件有:数据录入,图表,数据分析,导航,布局,网格,日程管理,样式,打印和工作流等,让您快速 ...
- Fiddler debug 拦截文件
前言 前端每次本地调试的需要重新build文件,而且如果当前文件是在另外一个项目中使用,则还需要拷贝到另外一个项目下面.这个工作很耗时.如果使用替换包,可以节省很多时间,也便于开发. 解决方案 用Fi ...
- sizeof运算符、虚函数、虚继承考点(待修改)
参考: http://blog.csdn.net/wangyangkobe/article/details/5951248 下面的文章解释有错误,不要看.......... 记住几句话: 编译器为每个 ...
- 【leetcode】Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...