微服务教程-使用Spring Cloud
来源:互联网 发布:淘宝申请介入问题描述 编辑:程序博客网 时间:2024/05/11 00:37
转载请注明出处 http://www.paraller.com 原文排版地址 点击获取更好阅读体验 分割符下面的配置代表:应用程序使用cloud 环境文件运行如果你使用了SPRING_PROFILES_ACTIVE变量,可以在 manifest.yml or, on Cloud Foundry Lattice, your Docker file.配置这个变量
在我的发布脚本中设置了APPLICATION_DOMAIN 环境变量,告诉服务外部的关联地址。在Eureka监控界面下点击刷新,30秒后你会看到你的服务已经注册好了。
使用 Ribbon 实现客户端的负载均衡
Spring Cloud 中关联其他服务使用的是 spring.application.name . 当我们构建 Spring Cloud-based 的服务的时候,这个值可以在很多上下文中被用到
为的是让客户端基于一些上下文信息,去决定哪一个服务将会被连接使用, Spring Cloud 把client-side load-balancing用途的 Ribbon集成进来了。看一下示例,直接使用 Eureka然后使用Ribbon.
```package passport;
import org.apache.commons.lang.builder.ToStringBuilder;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.cloud.client.ServiceInstance;import org.springframework.cloud.client.discovery.DiscoveryClient;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.cloud.netflix.feign.EnableFeignClients;import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.core.ParameterizedTypeReference;import org.springframework.http.HttpMethod;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Component;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.client.RestTemplate;
import java.util.List;
@SpringBootApplication@EnableEurekaClient@EnableFeignClientspublic class Application {
public static void main(String[] args) { new SpringApplicationBuilder(Application.class) .web(false) .run(args);}
}
@Componentclass DiscoveryClientExample implements CommandLineRunner {
@Autowiredprivate DiscoveryClient discoveryClient;@Overridepublic void run(String... strings) throws Exception { discoveryClient.getInstances("photo-service").forEach((ServiceInstance s) -
- 微服务教程-使用Spring Cloud
- 使用Spring Cloud Sleuth跟踪微服务
- Spring Cloud微服务
- spring cloud 微服务
- Spring Cloud 微服务示例
- Spring Cloud构建微服务
- 微服务框架-Spring Cloud
- 微服务Spring Cloud例子
- 微服务与Spring Cloud
- 微服务与Spring Cloud
- spring cloud 微服务架构
- 微服务架构(spring-cloud)
- 一、Spring Cloud 微服务
- Spring Cloud微服务 浅谈
- 使用Spring Cloud Netflix技术栈实施微服务架构
- 使用Spring Cloud和Docker构建微服务
- 综合使用spring cloud技术实现微服务应用
- 使用Spring Cloud和Docker构建微服务架构
- 10/21 dns域名解析与linux下操作虚拟机
- 洛谷 1339 [USACO09OCT]热浪Heat Wave 最短路
- 【Android】Dialog异常CalledFromWrongThreadException深入分析
- HttpClient中的三种超时设置区别
- CSR1010 基本信息
- 微服务教程-使用Spring Cloud
- Mybatis简单存储过程实例
- MyEclipse创建Working-set
- js之深入理解闭包问题。
- 谷歌镜像站
- centos7下设置成开机启动的java程序没有跑起来
- nginx配置允许跨域访问
- ajax遍历List<对象>的三种方式
- API Namespace zone