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...,为了让调用更简单,一般会在这些服务前端再封装一层,类似下 ...
随机推荐
- ES6入门之Proxy
1. 概述 Proxy 用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种『元编程』即对编程语言进行编程. 1.1 理解 Proxy 是在目标对象之前架设一层『拦截』,外部对对象的访问 ...
- 依赖注入 php
依赖注入:将当前类依赖的对象,以参数的方式注入到当前类中,简称依赖注入 <?php class Mi { public function size() { return '5.99寸全面屏'; ...
- 使用Ant打包工具
由于使用java,javac,jar等工具进行编译打包,即繁琐低效又容易出错,因此Ant出现了.Ant的出现就是专门为了打包编译java代码的,使用之前得稍微学一下.Ant的运行起来主要是依靠配置文件 ...
- python、mysql四-2:多表查询
一 介绍 本节主题 多表连接查询 复合条件连接查询 子查询 准备表 #建表 create table department( id int, name varchar() ); create tabl ...
- java代码调用exe(cmd命令)
public class ShellCommand{ public static void execCmd(String cmd, boolean wait) { execC ...
- SpringBoot 出现内置的Tomcat没有启动的情况
Tomcat未启动,也未报错 pom.xml文件中增加 <dependency> <groupId>org.springframework.cloud</groupId& ...
- BZOJ2306 [Ctsc2011]幸福路径[倍增]
这个有环的情况非常的讨厌,一开始想通过数学推等比数列的和,但是发现比较繁就不做了. 然后挖掘这题性质. 数据比较小,但是体力可以很接近1(恼怒),也就是说可能可以跳很多很多步.算了一下,大概跳了2e7 ...
- 我说CMMI之二:CMMI里有什么?--转载
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/dylanren/article/deta ...
- 还不会使用MyEclipse的Breadcrumb导航功能?再不看你就OUT了
MyEclipse CI 2019.4.0安装包下载 使用DevStyle Breadcrumb导航可以轻松地浏览工作区,只需遵循breadcrumb路径即可.DevStyle作为Eclipse插件提 ...
- 在CSS3中,可以利用transform功能来实现文字或图像的旋转、缩放、倾斜、移动这四种类型的变形处理
CSS3中的变形处理(transform)属 transform的功能分类 1.旋转 transform:rotate(45deg); 该语句使div元素顺时针旋转45度.deg是CSS 3的“Val ...