Spring Cloud 学习笔记-搭建微信h5牛牛棋牌房卡平台开发应用
2018-03-02 21:18
791 查看
微信h5牛牛棋牌房卡平台开发(Q-1687054422)提供基于REST的服务,在集群中主要用于服务管理。Eureka提供了基于Java语言的客户端组件,客户端组件实现了负载均衡的功能,为业务组件的集群部署创造了条件。使用该框架,可以将业务组件注册到Eureka容器中,这些业务组件可进行集群部署,Eureka主要维护这些服务的列表并自动检查它们的状态。
程序结构
创建Eureka Server
maven依赖<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies>在application.yml 更改spring boot 启动端口
server: port: 8761开启Eureka服务注解 @EnableEurekaServer
@EnableEurekaServer @SpringBootApplication public class EKServerApplication { public static void main(String[] args) { new SpringApplicationBuilder(EKServerApplication.class).run(args); } }启动springboot
[Thread-11] o.s.c.n.e.server.EurekaServerBootstrap: Initialized server context [main] s.b.c.e.t.TomcatEmbeddedServletContainer: Tomcat started on port(s): 8761 (http) [main] .s.c.n.e.s.EurekaAutoServiceRegistration: Updating port to 8761 [main] c.b.firstEkServer.EKServerApplication: Started EKServerApplication in 8.594 seconds (JVM running for 9.523)启动期间会出现一个无法连接到服务器的异常 这个是由于Eureka在启动的时候会把自己当作一个客户端去服务器抓取注册信息
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server增加如下配置启动时便不
bde8
会再出现该异常
eureka: client: registerWithEureka: false fetchRegistry: falseregisterWithEureka 声明是否将自己的信息注册到Eureka服务器,默认值为true。
fetchRegistry 声明是否到Eureka服务器中抓取注册信息,默认值为true。
在浏览器中访问 http://localhost:8761 查看Eureka控制台
创建服务提供者
依赖<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> </dependency>在 application.yml 中配置端口、Eureka实例名称和Eureka服务地址
server: port: 8080 spring: application: name: ek-provider eureka: instance: hostname: localhost client: serviceUrl: defaultZone: http://localhost:8761/eureka/创建一个简单的 REST 服务
@RestController public class HelloController { @RequestMapping("/hello") public String hello(HttpServletRequest request) { return "hello:" + request.getRequestURL(); } }开启Eureka客户端注解 @EnableEurekaServer
@EnableEurekaClient @SpringBootApplication public class EkProviderApplication { public static void main(String[] args) { new SpringApplicationBuilder(EkProviderApplication.class).run(args); } }启动之后在 Eureka 控制台可以看到服务提供者已经在 Eureka 中注册
创建服务调用者
依赖<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-ribbon</artifactId> </dependency>在 application.yml 中配置端口、Eureka实例名称和Eureka服务地址
server: port: 9000 spring: application: name: ek-invoke eureka: instance: hostname: localhost client: serviceUrl: defaultZone: http://localhost:8761/eureka/编写一个 REST 服务 调用服务提供者的 “/hello”
相关文章推荐
- 如何正确的在微信H5棋牌牛牛出租平台搭建开发中的UI图中取色
- 用C++实现跨微信h5牛牛平台棋牌开发搭建教程
- php语言之H5微信牛牛网站搭建开发平台技术栈
- P2P结构与微信Quorum牛牛h5棋牌源码租售平台搭建机制
- cocos2d-x 2.1.4学习笔记01:windows平台搭建cocos2d-x开发环境
- 《Spring 3.x 企业应用开发实战》学习笔记 第三章 ApplicationContext和BeanFactory区别
- cocos2dx游戏开发——微信打飞机学习笔记(九)——BulletLayer的搭建
- cocos2d-x学习笔记01:VS开发环境windows平台搭建
- cocos2dx游戏开发——微信打飞机学习笔记(四)——GameScene的搭建
- 《疯狂Workflow讲义——基于Activiti的工作流应用开发》学习笔记之一·环境搭建之编码问题
- cocos2dx游戏开发——微信打飞机学习笔记(五)——BackgroundLayer的搭建
- cocos2dx游戏开发——微信打飞机学习笔记(十)——碰撞检测的搭建
- cocos2dx游戏开发——微信打飞机学习笔记(三)——WelcomeScene的搭建
- PHP学习笔记(一):开发微信平台
- cocos2dx游戏开发——微信打飞机学习笔记(八)——EnemyLayer的搭建
- cocos2dx游戏开发——微信打飞机学习笔记(六)——PlayerLayer的搭建
- 学习Spring3.X 企业应用开发实战笔记(一)
- 《Spring 3.x 企业应用开发实战》学习笔记 第四章
- cocos2dx游戏开发——微信打飞机学习笔记(七)——Enemy的搭建
- spring学习笔记整理--02(搭建与测试Spring的开发环境)