Eureka 服务器架起来了(关于架设步骤參考博客《Linux 下 Eureka 服务器的部署》),如今怎样把我们要负载均衡的服务器(也就是从 Application Client 接收请求并返回一个响应的 Application Service)注冊到 Eureka?本文以一个演示样例介绍 Eureka Application Service 客户端的 Eureka 生命周期(包含启动时的注冊、侍服演示样例、关闭时的取消注冊)情况。相信读完本文之后,读者能够对 Eureka 的 Application Service 角色有了一个进一步了解,并且全然能够把自己的服务加进 Eureka。
        1. Eureka 服务器启动
        本文 demo 要求 Eureka Server 已经部署好,并已经启动。关于架设步骤參考博客《Linux 下 Eureka 服务器的部署》。
        Eureka 服务器启动以后,能够通过 http://serverIP:8080/eureka/ 或者 http://serverIP:8080/eureka/v2/apps/ 浏览已注冊到 Eureka 的 Application Service。

比方作者在开发环境 PC 訪问服务器端的 http://serverIP:8080/eureka/v2/apps/。页面返回结果例如以下:

<applications>
<versions__delta>1</versions__delta>
<apps__hashcode>UP_1_</apps__hashcode>
<application>
<name>EUREKA</name>
<instance>
<hostName>localhost.localdomain</hostName>
<app>EUREKA</app>
<ipAddr>127.0.0.1</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8080</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo
class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1404789864122</registrationTimestamp>
<lastRenewalTimestamp>1404798147096</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1404789841811</serviceUpTimestamp>
</leaseInfo>
<metadata class="java.util.Collections$EmptyMap" />
<appGroupName>UNKNOWN</appGroupName>
<homePageUrl>http://localhost.localdomain:8080/</homePageUrl>
<statusPageUrl>http://localhost.localdomain:8080/Status</statusPageUrl>
<healthCheckUrl>http://localhost.localdomain:8080/healthcheck</healthCheckUrl>
<vipAddress>eureka.mydomain.net</vipAddress>
<isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1404789864122</lastUpdatedTimestamp>
<lastDirtyTimestamp>1404789841863</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>
</applications>

apps__hashcode 是 1,能够看出眼下仅仅有一个 Application Service 注冊到了 Eureka Server,这个名为 Eureka 的 Application Service 仅仅有一个实例,就是这台 Eureka Server 它自己 - localhost.localdomain。为何 Eureka Server 自己也是一个 Application Service 呢?这也是 Eureka 架构健壮性 feature 之中的一个。Eureka Server 之间也会相互注冊,并且还会将注冊到自己的 Application Service 注冊给其它 Eureka Server,避免了一台 Eureka Server 宕机所造成的区域性服务瘫痪。
        2. Application Service 配置文件的编写
        我们的负载均衡服务器就用官方提供 demo 里的 sampleservice 下的 sample-eureka-service.properties 就可以,当然还要依据实际情况修正一下。比方把 eureka.name 改为我们自己定义的 Application 名以区分开其它服务,把 eureka.port(本服务将会执行并侍服请求的端口)改为我们的 Service 服务器开放的侍服端口 1935,eureka.serviceUrl.default(默认情况下本服务将要注冊到的 Eureka 服务器):http://serverIP:8080/eureka/v2/:

###Eureka Client configuration for Sample Eureka Service

#Properties based configuration for eureka client. The properties specified here is mostly what the users
#need to change. All of these can be specified as a java system property with -D option (eg)-Deureka.region=us-east-1
#For additional tuning options refer <url to go here> #Region where eureka is deployed -For AWS specify one of the AWS regions, for other datacenters specify a arbitrary string
#indicating the region.This is normally specified as a -D option (eg) -Deureka.region=us-east-1
eureka.region=default #Name of the application to be identified by other services eureka.name=sampleservice #Virtual host name by which the clients identifies this service
eureka.vipAddress=sampleservice.mydomain.net #The port where the service will be running and serving requests
eureka.port=1935 #For eureka clients running in eureka server, it needs to connect to servers in other zones
eureka.preferSameZone=false #Change this if you want to use a DNS based lookup for determining other eureka servers. For example
#of specifying the DNS entries, check the eureka-client-test.properties, eureka-client-prod.properties
eureka.shouldUseDns=false eureka.us-east-1.availabilityZones=default eureka.serviceUrl.default=http://serverIP:8080/eureka/v2/

3. 日志配置
        就用官方提供 demo 里的 sampleservice 下的 log4j.properties 就可以,当然还要依据实际须要修正一下,比方给 com.defonds.wms.module.server 包的输出级别设置为 DEBUG(log4j.properties 追加 log4j.logger.com.defonds.wms.module.server=DEBUG)。以方便我们研发期跟踪调试。

log4j.rootCategory=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p %C:%L [%t] [%M] %m%n

4. Application Service 启动时注冊 Eureka
        我们希望每台负载均衡服务器在启动时就注冊给 Eureka,以及时承担负载。注冊代码例如以下所看到的:

    private static final DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory.getInstance();

    private static final Logger logger = LoggerFactory.getLogger(SampleEurekaService.class);

    public void registerWithEureka() {
// Register with Eureka
DiscoveryManager.getInstance().initComponent(
new MyDataCenterInstanceConfig(),
new DefaultEurekaClientConfig());
ApplicationInfoManager.getInstance().setInstanceStatus(
InstanceStatus.UP);
}

第一句载入本地配置文件,initComponent 句依据配置初始化这台 Eureka Application Service。并且注冊到 Eureka Server,setInstanceStatus 句指示本台 Application Service 已启动。准备好侍服网络请求。
        5. Application Service 侍服网络请求
        Application Service 的 Eureka Server 初始化以及注冊是异步的。须要一段时间。我们想要在确认初始化并注冊成功之后,提供一个 Socket 服务,以供网络请求。demo 须要。这个服务是一次性的,仅仅提供一次 Socket 侍服。

侍服完一次请求后,本 Socket 服务就关闭,并将自己从 Eureka Server 取消注冊。

        String vipAddress = configInstance.getStringProperty(
"eureka.vipAddress", "sampleservice.mydomain.net").get();
InstanceInfo nextServerInfo = null;
while (nextServerInfo == null) {
try {
nextServerInfo = DiscoveryManager.getInstance()
.getDiscoveryClient()
.getNextServerFromEureka(vipAddress, false);
} catch (Throwable e) {
System.out
.println("Waiting for service to register with eureka.."); try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} }
}
System.out.println("Service started and ready to process requests.."); try {
ServerSocket serverSocket = new ServerSocket(configInstance
.getIntProperty("eureka.port", 8010).get());
final Socket s = serverSocket.accept();
System.out
.println("Client got connected..Processing request from the client");
processRequest(s); } catch (IOException e) {
e.printStackTrace();
}

Socket 侍服 processRequest 方法具体例如以下:

    private void processRequest(final Socket s) {
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(
s.getInputStream()));
String line = rd.readLine();
if (line != null) {
System.out.println("Received the request from the client.");
}
PrintStream out = new PrintStream(s.getOutputStream());
System.out.println("Sending the response to the client..."); out.println("Reponse at " + new Date()); } catch (Throwable e) {
System.err.println("Error processing requests");
} finally {
if (s != null) {
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} }

6. Application Service 关闭时取消注冊
        就像 Spring 管理的对象。初始化、销毁都统一管理起来一样。我们希望本台 Application Service 实例在关闭时也能将自身占用的系统资源释放出来(比方任务列表的线程关闭),并且取消掉 Eureka 服务器的注冊。

    public void unRegisterWithEureka() {
// Un register from eureka.
DiscoveryManager.getInstance().shutdownComponent();
}

7. 执行 demo
        如今我们把完整的 Application Service 整理一下。

/*
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package com.netflix.eureka; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import com.netflix.appinfo.MyDataCenterInstanceConfig;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.discovery.DefaultEurekaClientConfig;
import com.netflix.discovery.DiscoveryManager; /**
* Sample Eureka service that registers with Eureka to receive and process
* requests.
*
* <p>
* This example just receives one request and exits once it receives the request
* after processing it.
* </p>
*
* @author Karthik Ranganathan
*
*/
public class SampleEurekaService { private static final DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory
.getInstance(); private static final Logger logger = LoggerFactory
.getLogger(SampleEurekaService.class); public void registerWithEureka() {
// Register with Eureka
DiscoveryManager.getInstance().initComponent(
new MyDataCenterInstanceConfig(),
new DefaultEurekaClientConfig());
ApplicationInfoManager.getInstance().setInstanceStatus(
InstanceStatus.UP);
String vipAddress = configInstance.getStringProperty(
"eureka.vipAddress", "sampleservice.mydomain.net").get();
InstanceInfo nextServerInfo = null;
while (nextServerInfo == null) {
try {
nextServerInfo = DiscoveryManager.getInstance()
.getDiscoveryClient()
.getNextServerFromEureka(vipAddress, false);
} catch (Throwable e) {
System.out
.println("Waiting for service to register with eureka.."); try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} }
}
System.out.println("Service started and ready to process requests.."); try {
ServerSocket serverSocket = new ServerSocket(configInstance
.getIntProperty("eureka.port", 8010).get());
final Socket s = serverSocket.accept();
System.out
.println("Client got connected..Processing request from the client");
processRequest(s); } catch (IOException e) {
e.printStackTrace();
}
this.unRegisterWithEureka();
System.out.println("Shutting down server.Demo over."); } public void unRegisterWithEureka() {
// Un register from eureka.
DiscoveryManager.getInstance().shutdownComponent();
} private void processRequest(final Socket s) {
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(
s.getInputStream()));
String line = rd.readLine();
if (line != null) {
System.out.println("Received the request from the client.");
}
PrintStream out = new PrintStream(s.getOutputStream());
System.out.println("Sending the response to the client..."); out.println("Reponse at " + new Date()); } catch (Throwable e) {
System.err.println("Error processing requests");
} finally {
if (s != null) {
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} } public static void main(String args[]) {
SampleEurekaService sampleEurekaService = new SampleEurekaService();
sampleEurekaService.registerWithEureka();
} }

非常明显我们的 SampleEurekaService 类须要非常多依赖包,这些包都在 eureka-server-1.1.134.war 包里的 WEB-INF/lib 文件夹下,直接拷贝进我们 demo 的 CLASSPATH。不用一个个去找了,还避免了版本号冲突所带来的不必要麻烦。eureka-client-1.1.134.jar 能够去 http://mvnrepository.com/artifact/com.netflix.eureka/eureka-client/1.1.134 下载,或者直接 maven 依赖导入:

<dependency>
<groupId>com.netflix.eureka</groupId>
<artifactId>eureka-client</artifactId>
<version>1.1.134</version>
</dependency>

类完毕了、环境配置好了。接下来把第二、三步写好的 sample-eureka-service.properties、log4j.properties 也拷贝进 CLASSPATH。接下来就能够执行 demo 了。直接 run SampleEurekaService,发现报下面错误:
2014-07-07 17:01:50,141 WARN  com.netflix.config.sources.URLConfigurationSource:120 [main] [<init>] No URLs will be polled as dynamic configuration sources.
2014-07-07 17:01:50,144 INFO  com.netflix.config.sources.URLConfigurationSource:121 [main] [<init>] To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2014-07-07 17:01:50,178 INFO  com.netflix.config.DynamicPropertyFactory:281 [main] [getInstance] DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@6f25844f
2014-07-07 17:01:58,982 WARN  com.netflix.appinfo.PropertiesInstanceConfig:349 [main] [init] Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.
2014-07-07 17:02:00,140 WARN  com.netflix.discovery.DefaultEurekaClientConfig:95 [main] [init] Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.
2014-07-07 17:02:03,559 INFO  com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider:79 [main] [get] Setting initial instance status as: STARTING
Exception in thread "main" java.lang.RuntimeException: Failed to initialize DiscoveryClient!
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:235)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:169)
at com.netflix.discovery.DiscoveryManager.initComponent(DiscoveryManager.java:84)
at com.netflix.eureka.SampleEurekaService.registerWithEureka(SampleEurekaService.java:60)
at com.netflix.eureka.SampleEurekaService.main(SampleEurekaService.java:139)
Caused by: java.lang.IllegalArgumentException: DiscoveryClient: invalid serviceUrl specified!
at com.netflix.discovery.DiscoveryClient.getEurekaServiceUrlsFromConfig(DiscoveryClient.java:574)
at com.netflix.discovery.DiscoveryClient.getDiscoveryServiceUrls(DiscoveryClient.java:1180)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:186)
... 4 more
        原来 Archaius 不认 sample-eureka-service.properties。没有把我们的配置成功载入。Archaius 的官方说,Archaius 在默认情况下(就是不指定 properties 文件的情况下)会在应用的 classpath 中寻找一个名为 config.properties 的文件并读取其内容作为配置属性。
        好吧。我们把 sample-eureka-service.properties 重命名为 config.properties,然后又一次执行 SampleEurekaService。

这次执行成功了,没有再报错。

訪问服务器端的 http://serverIP:8080/eureka/v2/apps/。显演示样例如以下页面信息:

<applications>
<versions__delta>1</versions__delta>
<apps__hashcode>UP_2_</apps__hashcode>
<application>
<name>SAMPLESERVICE</name>
<instance>
<hostName>defonds-win7</hostName>
<app>SAMPLESERVICE</app>
<ipAddr>172.21.40.134</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">1935</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo
class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1404812488643</registrationTimestamp>
<lastRenewalTimestamp>1404812609036</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1404812458545</serviceUpTimestamp>
</leaseInfo>
<metadata class="java.util.Collections$EmptyMap" />
<appGroupName>UNKNOWN</appGroupName>
<homePageUrl>http://defonds-win7:1935/</homePageUrl>
<statusPageUrl>http://defonds-win7:1935/Status</statusPageUrl>
<healthCheckUrl>http://defonds-win7:1935/healthcheck</healthCheckUrl>
<vipAddress>sampleservice.mydomain.net</vipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1404812488643</lastUpdatedTimestamp>
<lastDirtyTimestamp>1404812513644</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>
<application>
<name>EUREKA</name>
<instance>
<hostName>localhost.localdomain</hostName>
<app>EUREKA</app>
<ipAddr>127.0.0.1</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8080</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo
class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1404812408111</registrationTimestamp>
<lastRenewalTimestamp>1404812618042</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1404812385938</serviceUpTimestamp>
</leaseInfo>
<metadata class="java.util.Collections$EmptyMap" />
<appGroupName>UNKNOWN</appGroupName>
<homePageUrl>http://localhost.localdomain:8080/</homePageUrl>
<statusPageUrl>http://localhost.localdomain:8080/Status
</statusPageUrl>
<healthCheckUrl>http://localhost.localdomain:8080/healthcheck
</healthCheckUrl>
<vipAddress>eureka.mydomain.net</vipAddress>
<isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1404812408111</lastUpdatedTimestamp>
<lastDirtyTimestamp>1404812385985</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>
</application>
</applications>

apps__hashcode 变成 2 了。

能够看出多了一个 defonds-win7 名字的 instance,它的 IP 地址正是我执行 demo 的 PC 地址 172.21.40.134。訪问 http://serverIP:8080/eureka/ 也能够看到该 instance:

        证明我们的 Application Service 已经成功注冊到该台 Eureka Server。

我们等待 Eureka Server 心跳訪问该 Application Service。或者自己手工訪问该 Application Service,以达成该服务器关闭条件,将其关闭。Application Service 成功取消注冊。

完整的 demo log 例如以下:
2014-07-08 10:06:54,124 INFO  com.netflix.config.sources.URLConfigurationSource:125 [main] [<init>] URLs to be used as dynamic configuration source: [file:/D:/javaprojects/test/bin/config.properties]
2014-07-08 10:06:54,259 INFO  com.netflix.config.DynamicPropertyFactory:281 [main] [getInstance] DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@2f774b9b
2014-07-08 10:08:32,464 WARN  com.netflix.appinfo.PropertiesInstanceConfig:349 [main] [init] Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.
2014-07-08 10:08:35,592 WARN  com.netflix.discovery.DefaultEurekaClientConfig:95 [main] [init] Cannot find the properties specified : eureka-client. This may be okay if there are other environment specific properties or the configuration is installed with a different mechanism.
2014-07-08 10:08:45,835 INFO  com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider:79 [main] [get] Setting initial instance status as: STARTING
2014-07-08 10:08:46,331 WARN  com.netflix.discovery.DiscoveryClient:1339 [main] [getZoneOffset] DISCOVERY: Could not pick a zone based on preferred zone settings. My zone - defaultZone, preferSameZone- false. Defaulting to defaultZone
2014-07-08 10:08:49,276 INFO  com.netflix.discovery.DiscoveryClient:646 [main] [fetchRegistry] Disable delta property : false
2014-07-08 10:08:49,277 INFO  com.netflix.discovery.DiscoveryClient:647 [main] [fetchRegistry] Single vip registry refresh property : null
2014-07-08 10:08:49,277 INFO  com.netflix.discovery.DiscoveryClient:648 [main] [fetchRegistry] Force full registry fetch : false
2014-07-08 10:08:49,277 INFO  com.netflix.discovery.DiscoveryClient:649 [main] [fetchRegistry] Application is null : false
2014-07-08 10:08:49,277 INFO  com.netflix.discovery.DiscoveryClient:650 [main] [fetchRegistry] Registered Applications size is zero : true
2014-07-08 10:08:49,278 INFO  com.netflix.discovery.DiscoveryClient:652 [main] [fetchRegistry] Application version is -1: true
2014-07-08 10:08:49,705 INFO  com.netflix.discovery.DiscoveryClient:992 [main] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/ with status code 200.
2014-07-08 10:08:49,706 INFO  com.netflix.discovery.DiscoveryClient:758 [main] [getAndStoreFullRegistry] Getting all instance registry info from the eureka server
2014-07-08 10:08:50,501 INFO  com.netflix.discovery.DiscoveryClient:765 [main] [getAndStoreFullRegistry] The response status is 200
2014-07-08 10:08:50,504 INFO  com.netflix.discovery.DiscoveryClient:1056 [main] [initScheduledTasks] Starting heartbeat executor: renew interval is: 30
2014-07-08 10:09:20,508 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-2] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:09:20,535 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-2] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_1_, is fetching remote regions? false 
2014-07-08 10:09:20,582 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-3] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 404.
2014-07-08 10:09:20,599 INFO  com.netflix.discovery.DiscoveryClient$HeartbeatThread:1415 [DiscoveryClient-3] [run] DiscoveryClient_SAMPLESERVICE/defonds-win7 - Re-registering apps/SAMPLESERVICE
2014-07-08 10:09:20,600 INFO  com.netflix.discovery.DiscoveryClient:509 [DiscoveryClient-3] [register] DiscoveryClient_SAMPLESERVICE/defonds-win7: registering service...
2014-07-08 10:09:20,648 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-3] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE with status code 204.
2014-07-08 10:09:20,649 INFO  com.netflix.discovery.DiscoveryClient:514 [DiscoveryClient-3] [register] DiscoveryClient_SAMPLESERVICE/defonds-win7 - registration status: 204
Waiting for service to register with eureka..
2014-07-08 10:09:30,513 INFO  com.netflix.discovery.DiscoveryClient$InstanceInfoReplicator:1476 [DiscoveryClient-2] [run] DiscoveryClient_SAMPLESERVICE/defonds-win7 - retransmit instance info with status UP
2014-07-08 10:09:30,514 INFO  com.netflix.discovery.DiscoveryClient:509 [DiscoveryClient-2] [register] DiscoveryClient_SAMPLESERVICE/defonds-win7: registering service...
2014-07-08 10:09:30,561 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-2] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE with status code 204.
2014-07-08 10:09:30,562 INFO  com.netflix.discovery.DiscoveryClient:514 [DiscoveryClient-2] [register] DiscoveryClient_SAMPLESERVICE/defonds-win7 - registration status: 204
2014-07-08 10:09:50,540 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:09:50,543 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-1] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions?

false 
2014-07-08 10:09:50,654 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 404.
2014-07-08 10:09:50,654 INFO  com.netflix.discovery.DiscoveryClient$HeartbeatThread:1415 [DiscoveryClient-1] [run] DiscoveryClient_SAMPLESERVICE/defonds-win7 - Re-registering apps/SAMPLESERVICE
2014-07-08 10:09:50,654 INFO  com.netflix.discovery.DiscoveryClient:509 [DiscoveryClient-1] [register] DiscoveryClient_SAMPLESERVICE/defonds-win7: registering service...
2014-07-08 10:09:50,674 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE with status code 204.
2014-07-08 10:09:50,674 INFO  com.netflix.discovery.DiscoveryClient:514 [DiscoveryClient-1] [register] DiscoveryClient_SAMPLESERVICE/defonds-win7 - registration status: 204
Service started and ready to process requests..
2014-07-08 10:10:20,548 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-2] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:10:20,551 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-2] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions? false 
2014-07-08 10:10:20,678 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 200.
2014-07-08 10:10:50,556 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:10:50,559 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-1] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions?

false 
2014-07-08 10:10:50,681 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-0] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 200.
2014-07-08 10:11:20,563 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:11:20,566 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-1] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions?

false 
2014-07-08 10:11:20,684 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 200.
2014-07-08 10:11:50,570 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-2] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:11:50,573 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-2] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions? false 
2014-07-08 10:11:50,687 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-1] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 200.
2014-07-08 10:12:20,579 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-0] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/delta with status code 200.
2014-07-08 10:12:20,582 INFO  com.netflix.discovery.DiscoveryClient$CacheRefreshThread:1542 [DiscoveryClient-0] [run] Completed cache refresh task for discovery. All Apps hash code is Local region apps hashcode: UP_2_, is fetching remote regions?

false 
2014-07-08 10:12:20,691 INFO  com.netflix.discovery.DiscoveryClient:992 [DiscoveryClient-0] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 200.
Client got connected..Processing request from the client
Received the request from the client.
Sending the response to the client...
2014-07-08 10:12:27,188 INFO  com.netflix.discovery.DiscoveryClient:992 [main] [makeRemoteCall] Finished a call to service url http://serverIP:8080/eureka/v2/ and url path apps/SAMPLESERVICE/defonds-win7 with status code 200.
2014-07-08 10:12:27,189 INFO  com.netflix.discovery.DiscoveryClient:603 [main] [unregister] DiscoveryClient_SAMPLESERVICE/defonds-win7 - deregister  status: 200
Shutting down server.Demo over.
        麻雀虽小五脏俱全,样例非常easy,但却完整地展现了一个 Application Service 客户端的 Eureka 生命周期。
        參考资料

Eureka 的 Application Service client的注冊以及执行演示样例的更多相关文章

  1. Eureka 的 Application Client client的执行演示样例

            上篇以一个 demo 演示样例介绍了 Eureka 的 Application Service 客户端角色.今天我们继续了解 Eureka 的 Application Client 客 ...

  2. Android平台调用Web Service:演示样例

    近期在学习Android,随着移动设备的流行,当软件走上商业化的道路,为了争夺市场,肯定须要支持Android的,所以開始接触了Android,只是仅仅了解皮毛就好,由于我们要做管理者嘛,懂点Andr ...

  3. Android网络(3):HttpClient作client,Tomcat Servlet作server的交互演示样例

    前面相继介绍了Android网络编程里的Socket传输图片.HttpURLConnection,今天看HttpClient. 第一部分:JavaEE版的Eclipse配置Tomcat [备注:开发后 ...

  4. C# 系统应用之注冊表使用具体解释

    在平时做项目时,我们有时会遇到注冊表的操作,比如前面我们须要获取IE浏览器地址栏的信息.获取"我的电脑"地址栏输入的目录信息.USB近期使用信息等.注冊表项是注冊表的基本组织单位, ...

  5. Android Binder分析二:Natvie Service的注冊

    这一章我们通过MediaPlayerService的注冊来说明怎样在Native层通过binder向ServiceManager注冊一个service,以及client怎样通过binder向Servi ...

  6. spring揭秘 读书笔记 二 BeanFactory的对象注冊与依赖绑定

    本文是王福强所著<<spring揭秘>>一书的读书笔记 我们前面就说过,Spring的IoC容器时一个IoC Service Provider,并且IoC Service Pr ...

  7. 关于jdbc注冊驱动的那点事

    看到非常多人写jdbc连接工具类的时候,都会写到Class.forName()去显示载入类,一写错点点就会抛出ClassNotFoundException,关于显示载入类,究竟会不会产生作用呢? 參考 ...

  8. 注冊成为Windows Phone开发人员而且解锁Windows Phone 8.1手机

    注冊成为Windows Phone开发人员而且解锁Windows Phone 8.1手机 上篇文章介绍了怎样使用Qt Creator和Visual Studio构建Windows Phone 8.1应 ...

  9. 黑马day07 登录注冊案例(一)

    简单介绍:依据三层架构的思想设计本案例. 1.搭建好开发环境 准备好须要的包和模拟数据库配置文件users.xml -->cn.itheima.dao -->cn.itheima.serv ...

随机推荐

  1. Python函数-闭包的概念

    一个函数和它的环境变量合在一起,就构成了一个闭包(closure).在Python中,所谓的闭包是一个包含有环境变量取值的函数对象.环境变量取值被保存在函数对象的__closure__属性中.比如下面 ...

  2. Linux下定时备份MySQL数据库的Shell脚本

    Linux下定时备份MySQL数据库的Shell脚本   对任何一个已经上线的网站站点来说,数据备份都是必须的.无论版本更新还是服务器迁移,备份数据的重要性不言而喻.人工备份数据的方式不单耗费大量时间 ...

  3. TCP/IP——链路层简记

    在TCP/IP协议族中链路层的主要目的有三个: 1,为IP模块发送和接受IP数据报. 2,为ARP模块发送ARP请求和接受ARP应答. 3,为RARP模块发送RARP请求和接受RARP应答. 链路层包 ...

  4. Hibernate 双向一对多的关联映射

    双向的一对多的关联关系是单项的一对多和单项的多对一的情况下产生的. 1.设计表结构 虽然关联关系变为双向的一对多,但是我们表结构不会发生改变,只是指向变了. 2.创建student对象 3.创建Gra ...

  5. hibernate4日志配置

    在平时运行程序时控制台有很对的日志打印,本文说明如何控制这些日志打印. 1.确定要使用日志的实现,我在这使用的是log4j. 2.加入log4j的api包slf4j-api.jar,log4j的转换包 ...

  6. 贪心:zoj3953 Intervals

    Description Chiaki has n intervals and the i-th of them is [li, ri]. She wants to delete some interv ...

  7. 【KM】BZOJ1937 [Shoi2004]Mst 最小生成树

    这道题拖了好久因为懒,结果1A了,惊讶∑( 口 || [题目大意] 给定一张n个顶点m条边的有权无向图.现要修改各边边权,使得给出n-1条边是这张图的最小生成树,代价为变化量的绝对值.求最小代价之和. ...

  8. SpringMVC 常用注解 详解

    SpringMVC 常用注解 详解 SpringMVC 常用注解 1.@RequestMapping                                      路径映射 2.@Requ ...

  9. bzoj 2440

    题意:有一个从小到大的由不包含平方约数的数组成的数列,从1开始,求第k项. “满足某种限制的数的第k个”+二分答案="前n个数有多少个数满足限制“ 求[1,n]中有多少个数没有平方约数,我们 ...

  10. python开发_pprint()

    python中的pprint.pprint(),类似于print() 下面是我做的demo: #python pprint '''python API中提供的Sample''' import json ...