## Example Overview
The eurekaexample requires 3 participants:
* acentralized eureka server for registration and discovery
* anexample service to register with eureka that exposes a REST endpoint
* anexample client that discovers the example service via discovery, and thenqueries the example service on it's
registered REST endpoint.
eureka例子需要3个参与者:
*用于注册和发现的集中式eureka服务器
*注册eureka的一个示例服务,它展示了一个REST端点
*通过发现示例服务的示例客户机,然后在其上查询示例服务注册REST端点。
### Setting up the Eureka server
1. Edit [eureka-server.properties]
(https://github.com/Netflix/eureka/blob/master/eureka-server/src/main/resources/eureka-server.properties)and uncomment the two settings that makes the demo server start up faster (viadisabling safeguards)
2. [Build](https://github.com/Netflix/eureka/wiki/Building-Eureka-Client-and-Server)the application.
3. Theabove build also sets up all the libraries needed for running the demo serviceand the demo client.
4.Copy the WAR artifact to your tomcat deployment directory under_$TOMCAT_HOME/webapps/
<pre><code>
cp ./eureka-server/build/libs/eureka-server-XXX-SNAPSHOT.war$TOMCAT_HOME/webapps/eureka.war
</pre></code>
5.Create (or add to) a setenv.sh in tomcat/bin/ with the following javaopts (these are for the demo server to start up fast, seeEurekaServerConfig.java for their documentation):
<pre>
JAVA_OPTS=" \
-Deureka.waitTimeInMsWhenSyncEmpty=0 \
-Deureka.numberRegistrySyncRetries=0"
</pre>
前面5步就是把工程打war包,扔到tomcat里面。在配置文件里面设置waitTimeInMsWhenSyncEmpty=0和numberRegistrySyncRetries=0就行了。
6.Start your tomcat server. Access_**http://localhost:8080/eureka**_to verify the information there. Your server'seureka client shouldregister itself in 30 seconds and you should see that information there.
启动Tomcat服务器。访问 http://localhost:8080/eureka
核实那里的信息。你的服务器的eureka客户端应该在30秒内注册,你应该看到那里的信息。
### Running the examples directly
1.Start up a local eureka server
2. Runthe example service first with
<code>./gradlew :eureka-examples:runExampleService</code>
andwait until you see "_Service started and ready to process requests.._"indicating that is had registered witheureka.
3. Run the example client with
<code>./gradlew :eureka-examples:runExampleClient</code>.
我没有通过gradlew运行,是直接在eclipse里面run as的application。
气死人问题系列:
我怎么都服务注册报错,“There is no known eureka server; cluster server list is empty”
找不到原因,跟代码也没看明白,最后看了篇帖子,http://blog.csdn.net/defonds/article/details/37592123
发现了关键信息一句话
虽然问题报的不一样,但是试着改了。果然……
改完,瞬间好了!
### Running the examples as anapp
1.Start up a local eureka server
2.Build a zip distribution with
<code>./gradlew :eureka-examples:distZip</code>
3. Inthe distribution run <code>./bin/ExampleEurekaService</code> and wait until you see "_Servicestarted and ready to process requests.._" indicating that is hadregistered with eureka.
4. Inthe distribution run <code>./bin/ExampleEurekaClient</code> to run the example client.
## Examples Provided
### ExampleEurekaService
Anexample service that registers itself witheureka. (Note: prefer the DIversion of creation in ExampleEurekaGovernatedService).
### ExampleEurekaGovernatedService
Thesame as the ExampleEurekaService, whereGovernator/Guice is usedto initialize everything. The gradle javaExec for this is <code>./gradlew:eureka-examples:runExampleGovernatedService</code> and thedistribution generated script is<code>./bin/ExampleEurekaGovernatedService</code>
### ExampleEurekaClient
Anexample use case of the eureka client to find a particular application/vip(in this case the example service) viaeureka for communication.
官方客户端调用例子把服务关掉了。