Spring Cloud Ribbon –进行安全呼叫
很简单,但是最近我为此感到困惑 –我必须对安全的远程服务进行基于Netflix Ribbon的客户端调用。 事实证明,使用Netflix Ribbon可以通过两种方式实现这一点,我将通过Spring Cloud对Ribbon库的出色支持来演示这一点。
在之前的两个博客文章中,我继续介绍了Spring Cloud Ribbon的基础知识和一些高级自定义 ,并继续同一示例,并假设我具有以下几方面的配置:
sampleservice:ribbon:listOfServers: someserver:80ReadTimeout: 5000MaxAutoRetries: 2
有了这个配置,我可以这样调用服务:
public class RestTemplateSample {@Autowiredprivate RestTemplate restTemplate;@Overridepublic MessageAcknowledgement sendMessage(Message message) {String pongServiceUrl = "http://sampleservice/message";HttpEntity<Message> requestEntity = new HttpEntity<>(message);ResponseEntity<MessageAcknowledgement> response = this.restTemplate.exchange(pongServiceUrl, HttpMethod.POST, requestEntity, MessageAcknowledgement.class, Maps.newHashMap());return response.getBody();}}
因此,现在,如果远程服务受到保护,则第一种方法(可能是首选方法)实际上非常简单,只需向“命名”客户端添加其他配置以表明远程服务是安全的,请注意,端口也必须是安全的。适当指定。
sampleservice:ribbon:listOfServers: someserver:443ReadTimeout: 5000MaxAutoRetries: 2IsSecure: true
第二种有效的方法是简单地更改url以指示您正在调用https端点,这一次不需要“ IsSecure”配置:
public class RestTemplateSample {@Autowiredprivate RestTemplate restTemplate;@Overridepublic MessageAcknowledgement sendMessage(Message message) {String pongServiceUrl = "https://sampleservice/message";HttpEntity<Message> requestEntity = new HttpEntity<>(message);ResponseEntity<MessageAcknowledgement> response = this.restTemplate.exchange(pongServiceUrl, HttpMethod.POST, requestEntity, MessageAcknowledgement.class, Maps.newHashMap());return response.getBody();}}
翻译自: https://www.javacodegeeks.com/2016/02/spring-cloud-ribbon-making-secured-call.html
Spring Cloud Ribbon –进行安全呼叫相关推荐
- Spring Cloud Ribbon(服务消费者)
Spring Cloud Ribbon 是一个基于Http和TCP的客户端负载均衡工具,基于Netflix Ribbon实现的.它不像服务注册中心.配置中心.API网关那样独立部署,但是它几乎存在于每 ...
- 基于Spring cloud Ribbon和Eureka实现客户端负载均衡
前言 本案例将基于Spring cloud Ribbon和Eureka实现客户端负载均衡,其中Ribbon用于实现客户端负载均衡,Eureka主要是用于服务注册及发现: 传统的服务端负载均衡 常见的服 ...
- resttemplate 请求重试_使用Spring Cloud Ribbon重试请求
使用Spring Cloud Ribbon重试请求 在微服务调用中,一些微服务圈可能调用失败,通过再次调用以达到系统稳定性效果,本文展示如何使用Ribbon和Spring Retry进行请求再次重试调 ...
- java B2B2C springmvc mybatis多租户电子商城系统-Spring Cloud Ribbon
Spring Cloud Ribbon是一个基于HTTP和TCP的客户端负载均衡工具,它基于Netflix Ribbon实现. 通过Spring Cloud的封装,可以让我们轻松地将面向服务的REST ...
- Spring Cloud微服务笔记(四)客户端负载均衡:Spring Cloud Ribbon
客户端负载均衡:Spring Cloud Ribbon 一.负载均衡概念 负载均衡在系统架构中是一个非常重要,并且是不得不去实施的内容.因为负载均衡对系统的高可用性. 网络压力的缓解和处理能力的扩容的 ...
- 为Spring Cloud Ribbon配置请求重试(Camden.SR2+)
当我们使用Spring Cloud Ribbon实现客户端负载均衡的时候,通常都会利用@LoadBalanced来让RestTemplate具备客户端负载功能,从而实现面向服务名的接口访问(原理可见& ...
- Spring Cloud Ribbon 负载均衡客户端调用示例
承接 Spring Cloud 最简入门示例 这一篇, 本篇演示如何使用负载均衡客户端 Ribbon 调用在Eureka注册的服务. Ribbon 是什么? Ribbon是Netflix 的开源项目, ...
- Java中Spring Cloud Ribbon
Spring Cloud Ribbon是一个基于HTTP和TCP的客户端负载均衡工具,它基于Netflix Ribbon实现.通过Spring Cloud的封装,可以让我们轻松地将面向服务的REST模 ...
- Spring Cloud的负载均衡Spring Cloud Ribbon和Spring Cloud Feign
一.客户端负载均衡:Spring Cloud Ribbon. Spring Cloud Ribbon是基于HTTP和TCP的客户端负载工具,它是基于Netflix Ribbon实现的.通过Spring ...
最新文章
- 几何分布的期望和方差
- 运维工程师该干什么学些什么
- Pytorch的backward()相关理解
- 获得本机的IP,掩码和网关
- STM32F4 HAL库开发 -- 温度传感器(DS18B20)
- Out of Hay
- Linux Bond 技术学习资料
- P2012 拯救世界2(指数型生成函数)
- java01基础简介
- 【牛客 - 368C】流星雨(概率dp,乘法逆元)
- 赋能网安生态通信服务器操作系统,紫光展锐打造操作系统生态,赋能万物互联智能时代...
- js 字符串、数值之间的转换
- Window插件获取窗口坐标
- java关闭文件句柄_java-JAI关闭文件句柄为时过早吗?
- pytorch:定义自己的网络结构
- 获取别人_职场潜规则:要想获取别人信任与更多机会,先要学会勇于承担责任...
- 360粉碎文件可以恢复吗,如何恢复360强力删除的文件
- SpringBoot项目实战,附源码
- Java程序设计(二)
- 概率论--贝叶斯法则