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的更多相关文章

  1. 微服务架构的服务与发现-Spring Cloud

    1 为什么需要服务发现 简单来说,服务化的核心就是将传统的一站式应用根据业务拆分成一个一个的服务,而微服务在这个基础上要更彻底地去耦合(不再共享DB.KV,去掉重量级ESB),并且强调DevOps和快 ...

  2. Spring Cloud(一):服务治理技术概览【Finchley 版】

    Spring Cloud(一):服务治理技术概览[Finchley 版]  发表于 2018-04-14 |  更新于 2018-05-07 |  Spring Cloud Netflix 是 Spr ...

  3. 十分钟了解 spring cloud

    1 为什么需要服务发现 简单来说,服务化的核心就是将传统的一站式应用根据业务拆分成一个一个的服务,而微服务在这个基础上要更彻底地去耦合(不再共享DB.KV,去掉重量级ESB),并且强调DevOps和快 ...

  4. Spring Cloud Alibaba - Spring Cloud Stream 整合 RocketMQ

    Spring Cloud Stream 简介 在微服务的开发过程中,可能会经常用到消息中间件,通过消息中间件在服务与服务之间传递消息,不管你使用的是哪款消息中间件,比如RabbitMQ.Kafka和R ...

  5. Spring Cloud Stream消费失败后的处理策略(四):重新入队(RabbitMQ)

    应用场景 之前我们已经通过<Spring Cloud Stream消费失败后的处理策略(一):自动重试>一文介绍了Spring Cloud Stream默认的消息重试功能.本文将介绍Rab ...

  6. Spring Cloud Stream消费失败后的处理策略(三):使用DLQ队列(RabbitMQ)

    应用场景 前两天我们已经介绍了两种Spring Cloud Stream对消息失败的处理策略: 自动重试:对于一些因环境原因(如:网络抖动等不稳定因素)引发的问题可以起到比较好的作用,提高消息处理的成 ...

  7. Spring Cloud Stream消费失败后的处理策略(二):自定义错误处理逻辑

    应用场景 上一篇<Spring Cloud Stream消费失败后的处理策略(一):自动重试>介绍了默认就会生效的消息重试功能.对于一些因环境原因.网络抖动等不稳定因素引发的问题可以起到比 ...

  8. Spring Cloud Stream消费失败后的处理策略(一):自动重试

    之前写了几篇关于Spring Cloud Stream使用中的常见问题,比如: 如何处理消息重复消费 如何消费自己生产的消息 下面几天就集中来详细聊聊,当消息消费失败之后该如何处理的几种方式.不过不论 ...

  9. spring cloud 学习(6) - zuul 微服务网关

    微服务架构体系中,通常一个业务系统会有很多的微服务,比如:OrderService.ProductService.UserService...,为了让调用更简单,一般会在这些服务前端再封装一层,类似下 ...

随机推荐

  1. thinkjs-定时任务

    thinkjs-定时任务 配置 原文文档 定时任务的配置文件为 src/config/crontab.js(多模块项目下配置文件为 src/common/config/crontab.js,也支持在每 ...

  2. python视频学习笔记5(高级变量的类型)

    知识点回顾: Python 中数据类型可以分为 **数字型** 和 **非数字型*** 数字型 * 整型 (`int`) * 浮点型(`float`) * 布尔型(`bool`) * 真 `True` ...

  3. symfony2学习笔记——控制器

    //获取get过来的参数 $val = $request->query->get('aaa'); //获取post过来的参数 //$val = $request->request-& ...

  4. docker私有仓库registry的使用

    1.registry的安装 关于docker registry的安装,可以说简单的不能再简单了,docker run一个容器就好了,也就是一条命令的事 docker run -d -p : --res ...

  5. Ceph实战入门之安部署篇

    最近Ceph官方发布了luminous长久支持版,新版本增加了很多有意思的功能,但是入门还是先从部署安装开始. 环境说明 在Win10下安装VMware® Workstation 12 Pro软件,用 ...

  6. Qt5.12.0交叉编译

    Qt5.12.0 交叉编译 源码配置 修改 qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf 文件 MAKEFILE_GENERATOR = UNIX C ...

  7. POJ1185炮兵阵地(DP状态压缩)

    问题描述 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P&quo ...

  8. 【CF208E】Blood Cousins

    题目大意:给定一个 N 个点的森林,M 个询问,每次询问对于点 u 来说,有多少个点和 u 有相同的 K 级祖先. 题解:线段树合并适合处理子树贡献的问题. 发现要回答这个询问在点 u 处计算很困难, ...

  9. DB2中常见sqlCode原因分析

    000 | 00000 | SQL语句成功完成 01xxx | SQL语句成功完成,但是有警告 +012 | 01545 | 未限定的列名被解释为一个有相互关系的引用 +098 | 01568 | 动 ...

  10. Django-ORM和MySQL事务及三大范式介绍

    Django中操作操作数据库这里需要改一个数据: 模型层:就是与跟数据库打交道 ORM查询: 一.单表操作必知必会13条: orm默认都是惰性查询: 1.all() 查询所有 2.filter() 筛 ...