基础架构:
Eureka的基本功能:
eueka按逻辑上可以划分为3个模块,eureka-server,service-provider,service-consumer
eureka-server:服务端,提供服务注册和发现
eureka-client-service-provider:服务端,服务提供者,通过http rest告知服务端注册,更新,取消服务
eureka-client-service-consumer:客户端,服务消费者,通过http rest从服务端获取需要服务的地址列表,然后配合一些负载均衡策略(ribbon)来调用服务端服务。
值得注意的一点,不同于其他服务注册与发现(zookeeper需要单独以中间件的形式部署集群server),以上3个角色都是逻辑角色,甚至可以在相同的jvm进程上
注意:在该默认配置下,注册中心也会将自己作为客户端尝试注册自己,因此要禁用客户端注册行为
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
项目结构:
4.0.0
micronservice
micronservice
pom
1.0
provider-user
consumer-order
org.springframework.boot
spring-boot-starter-parent
2.1.8.RELEASE
micronservice
http://www.example.com
UTF-8
1.7
1.7
org.springframework.cloud
spring-cloud-dependencies
Finchley.M9
pom
import
junit
junit
4.11
test
ch.qos.logback
logback-core
ch.qos.logback
logback-classic
org.springframework.boot
spring-boot-maven-plugin
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
maven-surefire-plugin
2.22.1
maven-jar-plugin
3.0.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
maven-site-plugin
3.7.1
maven-project-info-reports-plugin
3.0.0
Eureka服务器的配置:
4.0.0
com.qyx
eureka01
1.0-SNAPSHOT
eureka01
http://www.example.com
UTF-8
1.7
1.7
junit
junit
4.11
test
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
1.4.3.RELEASE
org.springframework.boot
spring-boot-starter-security
maven-clean-plugin
3.1.0
maven-resources-plugin
3.0.2
maven-compiler-plugin
3.8.0
maven-surefire-plugin
2.22.1
maven-jar-plugin
3.0.2
maven-install-plugin
2.5.2
maven-deploy-plugin
2.8.2
maven-site-plugin
3.7.1
maven-project-info-reports-plugin
3.0.0
application.yml文件的配置
server:
port: 10000
#因为当前的eureka是单机的,所以我们需要做一些配置
#注意:在该默认配置下,注册中心也会将自己作为客户端尝试注册自己,因此要禁用客户端注册行为
#eureka.client.register-with-eureka=false
#eureka.client.fetch-registry=false
eureka:
client:
register-with-eureka: false #禁止自己当做服务注册
fetch-registry: false #屏蔽注册信息
service-url:
defaultZone: http://user:123@localhost:10000/eureka
#security:
# basic:
# enabled: true #开启安全配置,也就是需要密码,如果不需要设置为fasle即可,注意这个参数必须放在application.yml文件中,不允许放在bootstrap.yml
# user:
# password: 123
# name: user #在配置了用户名和密码后我们可以修改地址的访问风格为 curl风格
packagecom.qyx;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.cloud.netflix.eureka.server.EnableEurekaServer;import javax.swing.*;
@EnableEurekaServer//通过@EnableEurekaServer注解启动一个服务注册中心简言之将当前项目标注为eurekaServer
@SpringBootApplicationpublic classEurekaApp {public static voidmain(String[] args)
{
SpringApplication.run(EurekaApp.class);
}
}
登录service-url.defaultZone: http://user:123@localhost:10000/eureka 里面配置的Eureka信息面板的地址