Eureka 的 Application Client 客户端的运行示例

本文详细介绍了Eureka服务发现组件的应用,通过实例展示了Eureka客户端如何在分布式架构中进行服务注册与发现,同时探讨了其在集群环境中的运行机制和负载均衡策略。
摘要由CSDN通过智能技术生成
        上篇以一个 demo 示例介绍了 Eureka 的 Application Service 客户端角色。今天我们继续了解 Eureka 的 Application Client 客户端,以一个简单的交互示例,介绍 Application Client 是如何使用 Eureka 获取 Application Service 实例并发送请求的。
        上篇《 Eureka 的 Application Service 客户端的注册以及运行示例》使用了一个 Socket 服务做为 demo,本文示例配合该文,将以一个 Socket 客户端对该服务进行请求。
        1. Eureka 服务器启动
        本文 demo 要求 Eureka Server 已经部署好,并已经启动。关于架设步骤参考博客《 Linux 下 Eureka 服务器的部署》。
        2. Application Service 服务启动
        直接将《 Eureka 的 Application Service 客户端的注册以及运行示例》中的小 demo 跑起来(Socket Server 启动,开始侍服网络请求)。
        3. Application Client 配置文件的编写
        我们的 Application Client 就用官方提供 demo 里的 sampleclient 下的 sample-eureka-client.properties 即可,当然还要根据实际情况修正一下,比如把 eureka.serviceUrl.default(默认情况下本客户端将要注册到的 Eureka 服务器): http://serverIP:8080/eureka/v2/
###Eureka Client configuration for Sample Eureka Client


#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=sampleEurekaClient


#Virtual host name by which the clients identifies this service
#eureka.vipAddress=eureka.mydomain.net


#The port where the service will be running and servicing requests
#eureka.port=80


#For eureka clients running in eureka server, it needs to connect to servers in other zones
eureka.preferSameZone=true


#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/

        4. 日志配置
        就用官方提供 demo 里的 sampleclient 下的 log4j.properties 即可,当然还要根据实际需要修正一下,比如给 com.netflix.eureka 包的输出级别设置为 DEBUG(log4j.properties 追加 log4j.logger.com.netflix.eureka=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
log4j.logger.com.netflix.eureka=DEBUG

        5. 寻找本次请求的 Application Service 实例
        客户端在向 Application Service 请求之前得先从 Eureka Server 拿到侍服本次请求的 Application Se
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值