resttemplate

springcloud-sleuth+zipkin入门一

淺唱寂寞╮ 提交于 2019-12-07 10:14:52
说明 zipkin是twitter公司基于Google的drapper论文,创建一套分布式、服务计时框架,可以用于链路跟踪。目前有的java版本的实现有DropWizard zipkin和Springcloud-sleuth+zipkin等。本文是搭建Springcloud的入门实例。 重要概念 trace:个人理解,是一条链路的抽象,表示了一次完成的链路信息。traceid是该链路的唯一标识 span:是链路调用的节点,是链路上一次方法执行的过程。spanId是该过程的标识,同时span可以通过添加tag的方式附加业务信息。 Springcloud针对链路节点过程抽象了四种类型: sr:server receive服务端接收 ss:server send 服务端发送 cr: client receive 客户端接收 cs:Client send 客户端发送。 下图说明了Springsleuth的链路调用图: 引入上下级span关系后可以形成下面链路图: 搭建Springcloud-sleuth+zipkin 1环境说明 开发IDE:intellij IDEA2017 jdk:1.8 maven:3.3.9 springboot:1.5.2RELEASE springcloud:Camden.SR7 2创建zipkin服务器 创建maven工程,并在pom

400 Bad Request when uploading byte[] with Spring RestTemplate to SpringMVC rest endpoint

左心房为你撑大大i 提交于 2019-12-07 06:15:12
问题 I am trying to upload a byte[] that contains an image to my Spring rest service (running in Spring Boot, btw) as a MultipartFile with my client running Spring RestTemplate and am getting HttpClientErrorException: 400 Bad Request. My endpoint: @RequestMapping(value="/scale/{percent}", method= RequestMethod.POST) public ResponseEntity scaleImage(@PathVariable("percent") float percent, @RequestParam("file") MultipartFile file) { try { if (!file.isEmpty()) { byte [] result = transformService

POST request with Spring RestTemplate- BadRequest 400

一曲冷凌霜 提交于 2019-12-07 02:22:27
Hope a Spring guru could help me on this, Iam developing a multi web servces application, All these Web Services are based on a Jar called based-server, which got all base classes which can be inherited where ever required. So this base-server project i have a BaseClient class which has a spring RestTemplate property. when i try to use this client (of cause inheriting) in a actual implemented web service class, when i try to do POST request it gives me http 400 Bad Request error. However it works without giving any trouble for GET requests. Appriciate if someone can point out where i got it

《微服务架构基础 Spring Boot+Spring Cloud + Docker》学习笔记

走远了吗. 提交于 2019-12-07 01:33:25
之前写了一篇博文,介绍得太片面,后面觉得文章写得太水了,就重新把书看了一遍,将书上前5章的代码一一实现。这篇文章主要介绍微服务架构,后面会在写一篇介绍docker。 全书将搭建了一个使用Spring Cloud一系列的架构,没有深层次的业务,只有两个简单的方法。涉及到每个技术点都有讲解,读完会对微服务会大致有印象。对Spring Cloud深入了解需要到官网查看文档: https://cloud.spring.io/spring-cloud-static/Greenwich.RELEASE/single/spring-cloud.html 。总的来说是一本不涉及较深知识点的工具书,读完后自己实现一个或把源码拿来看还是有所收获的。 项目架构图如: 前言 全书共分为四部分:第一部分“微服务概述”,主要讲解微服务的由来、概念、特点和微服务架构等;第二部分“微服务的开发”,主要讲解微服务开发框架Spring Boot的使用;第三部分“微服务架构的构建”,主要讲解如何使用Spring Cloud的相关组件来构建微服务架构;第四部分“微服务的部署”,主要讲解Docker技术,以及如何在Docker中部署微服务项目。 主要技术点:Spring Cloud Eureka实现服务发现;Spring Cloud Ribbon实现客户端负载均衡;Spring Cloud Hystrix

springcloud微服务简单搭建

删除回忆录丶 提交于 2019-12-07 01:15:30
一、搭建注册中心 1、创建一个demo项目,demo点击右键创建module 2、设置项目参数 3、选择spring cloud discovery,一直下一步,最后点击完成,创建注册中心 4、将application.properties文件修改为application.yml(格式比较清晰),复制下面参数 server: port: 8001 # 服务端口 eureka: instance: hostname: localhost # 设置主机名 client: registerWithEureka: false # 是否向 Eureka 注册服务。该应用为服务注册中心,不需要自注册,设置为 false fetchRegistry: false # 是否检索服务。该应用为服务注册中心,职责为注册和发现服务,无需检索服务,设置为 false serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ # 注册中心url spring: application: name: eurka-server #服务名称 5、在项目启动类中添加@EnableEurekaServer注解 6、启动项目访问http://localhost:8001/,8001是配置文件中设置的端口号

spring-clound 学习打卡4:简单入门-熔断器-(Hystrix) 【Greenwich.SR1版本】

自闭症网瘾萝莉.ら 提交于 2019-12-07 01:05:14
spring-clound 学习打卡4:简单入门-熔断器-(Hystrix) 【Greenwich.SR1版本】 一、微服务中的雪崩效应简述 微服务架构中,一般根据业务功能,划分成一个又一个的服务。 服务和服务之间,一般通过rpc或者http调用。本系列入门学习打卡教程中的第二和第三章,讲的是利用ribbon 和feign 进行访问服务的例子。 为了提高整个系统的稳定性和可用性,一般单个服务,会部署成集群模式,从而不会因为一个服务挂掉了,导致整个系统Bug 或者不可用的情况。 不过,有这么一种情况,如果某一个服务异常,那么访问这个服务的线程就会被阻塞掉。如果大量的请求请求到这个服务,那么资源会被迅速耗费掉。从而导致这个服务瘫痪的情况。 而因为这个服务的瘫痪,消耗掉了系统的资源,那么整个系统没有资源了,进而影响到其他的服务,从而出现大面积服务瘫痪的情况。这就是小编理解的雪崩的情况。 二、准备工作。 启动第一章的server 和一个client, 端口8763. 工程传送门: https://github.com/unnunique/SpringCloundDakaLearning/tree/master/Chapter-4 三、利用熔断器解决雪崩效应,提高整个系统的可用性。 如下是微服务架构中,客户端【一般是手机端或者浏览器端】访问服务的架构大致如下。 较底层的服务如果出现故障

Need help on RestTemplate Post Request with Body Parameters?

徘徊边缘 提交于 2019-12-06 22:51:16
问题 I have a rest api url and submitted the same as POST request with body (user name, password, other parameters) via Rest Client (restclient-ui-2.4-jar-with-dependencies) and it got worked fine without any issues. Ex: URL: https://test.com/cgi-bin/testing/api Body: username=testuser&password=pass123&id=13002&name=raju The same is not working fine when i used Spring RestTemplate postForObject(url, varmap, Employee.class) method. Can someone help me with a simple example where the request is a

spring RestTemplate 出现 NoHttpResponseException 和 ConnectionTimeoutException

怎甘沉沦 提交于 2019-12-06 15:07:18
使用 httpclient.4.5.6 springboot 2.0.8RELEASE RetryExec.java CloseableHttpResponse execute() try { return this.requestExecutor.execute(route, request, context, execAware); } catch(final IOException ex) { if (retryHandler.retryRequest(ex.execCount, context) { } else { if (ex instanceof NoHttpResponseException) { } } } @Configuration public class RestTemplateConfig { // builder.build();的并发量是5,不如 new RestTemplate() 默认200 @Bean public RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } } 这样建的RestTemplate 没有重发 NoHttpResponseException和org.apache.http.conn

springcloud 入门

主宰稳场 提交于 2019-12-06 14:29:47
1、springcloud 简介 2、 注册中心 eureka Springcloud 简介 简介 Spring Cloud是一系列框架的有序集合。它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册、配置中心、消息总线、负载均衡、断路器、数据监控等,都可以用Spring Boot的开发风格做到一键启动和部署。Spring Cloud并没有重复制造轮子,它只是将目前各家公司开发的比较成熟、经得起实际考验的服务框架组合起来,通过Spring Boot风格进行再封装屏蔽掉了复杂的配置和实现原理,最终给开发者留出了一套简单易懂、易部署和易维护的分布式系统开发工具包。 详细介绍: https://baike.so.com/doc/25751000-26884657.html 配套参考资料: https://projects.spring.io/spring-cloud/ springcloud项目官方主页 https://springcloud.cc/ springcloud中文网 有很详细的翻译文档 http://springcloud.cn/ springcloud中文论坛 Springcloud 版本 pom 文件生成可借助网站: https://start.spring.io/ 原有的单体项目最终会被演化成下面

springcloud简介

那年仲夏 提交于 2019-12-06 14:27:18
Springcloud 简介 简介 Spring Cloud是一系列框架的有序集合。它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册、配置中心、消息总线、负载均衡、断路器、数据监控等,都可以用Spring Boot的开发风格做到一键启动和部署。Spring Cloud并没有重复制造轮子,它只是将目前各家公司开发的比较成熟、经得起实际考验的服务框架组合起来,通过Spring Boot风格进行再封装屏蔽掉了复杂的配置和实现原理,最终给开发者留出了一套简单易懂、易部署和易维护的分布式系统开发工具包。 详细介绍: https://baike.so.com/doc/25751000-26884657.html 配套参考资料: https://projects.spring.io/spring-cloud/ springcloud项目官方主页 https://springcloud.cc/ springcloud中文网 有很详细的翻译文档 http://springcloud.cn/ springcloud中文论坛 这样的架构解决了单体项目几点问题 1、zuul网关解决了服务调用安全性的问题 2、服务注册与发现(注册中心)eureka解决了各层服务耦合问题,它是微服务架构的核心,有它才能将单体项目拆解成微服务架构 3、Eureka集群解决了微服务中