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. Cesium-entiy闪烁范例

    // name:"圆闪烁", function f1() { var x=1; var flog=true; viewer.entities.add({ name:"圆形 ...

  2. 安装Anaconda3-201812详解

    Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项.  因为包含了大量的科学包,Anaconda 的下载文件比较大(约 531 MB), ...

  3. emwin之窗口ID的唯一性

    @2019-04-30 [小记] emwin窗口ID是唯一的 emwin多次创建同一窗口,则窗口句柄不同,多次删除窗口采取LIFO机制,即最新创建的窗口被首先删除 获取多次创建同一窗口的ID,准确位置 ...

  4. linux系统很卡的基本排查方法

    1. 查看内存使用情况 free -g 当观察到free栏已为0的时候,表示内存基本被吃完了,那就释放内存吧(释放内存参考上篇文章) 2. 查看磁盘使用情况 df -h 当发现磁盘使用率很高时,那就要 ...

  5. 使用TortoiseGit,设置ssh方式连接git仓库。

    开始设置之前的准备:建立项目文件夹,初始化git仓库(右键 git  init),右键打开 git bash ,git pull “仓库地址”, 把网站上的仓库代码拉取下来. TortoiseGit使 ...

  6. NFS原理

    1.什么是NFS? 全称 network file system 网络文件系统 通过网络存储和组织文件的一种方法或机制. 什么是文件系统? 2.为什么要用共享存储? 前端所有的应用服务器接收到用户上传 ...

  7. UVA - 1649 Binomial coefficients (组合数+二分)

    题意:求使得C(n,k)=m的所有的n,k 根据杨辉三角可以看出,当k固定时,C(n,k)是相对于n递增的:当n固定且k<=n/2时,C(n,k)是相对于k递增的,因此可以枚举其中的一个,然后二 ...

  8. Github首次使用,上传代码

    参考博客:https://blog.csdn.net/zhangsiyao11/article/details/77007684 1.首先下载客户端github下载地址为 https://github ...

  9. SP Flash Tool版本对应MTK处理器型号速查(SP Flash Tool Download)

    SP Flash Tool For Windows Download https://monkey8.pipipan.com/dir/19250369-32189369-ac1637/ SP Flas ...

  10. WSL中使用npm install报错

    报错内容类似下面的格式.具体解决方法请看这里:https://github.com/Microsoft/WSL/issues/14 着重关注 https://github.com/Microsoft/ ...