服务注册中心 Eureka actuator微服务信息完善
现在存在的问题是,服务提供者没有具体的IP地址,在实际生产中,集群是不同的服务器不同的端口提供服务,所以注册中心需要知道具体的提供者的IP和端口和服务名称。
1.服务名称修改
在8001和8002的yml中修改配置:
server:
port: 8001
spring:
application:
name: cloud-payment-service
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: org.gjt.mm.mysql.Driver
url: jdbc:mysql://localhost:3306/standarddb?userUnicode=true&characterEncoding=utf-8&useSSL=false
username: sa
password: HRBJYKJ-Battery
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.atguigu.springcloud.entities
eureka:
client:
#表示是否将自己注册进EurekaServer,默认true
register-with-eureka: true
#是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡。
fetch-registry: true
service-url:
defaultZone: http://eurreka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版
#主机名实例
instance:
instance-id: paymet8001
修改8002的yml配置:
server: port: 8002 spring: application: name: cloud-payment-service datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/standarddb?userUnicode=true&characterEncoding=utf-8&useSSL=false username: sa password: HRBJYKJ-Battery mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.atguigu.springcloud.entities eureka: client: #表示是否将自己注册进EurekaServer,默认true register-with-eureka: true #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡。 fetch-registry: true service-url: defaultZone: http://eurreka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版 #主机名实例 instance: instance-id: paymet8002
查看修改后的结果:
实例名称好处是可根据具体提供的业务定义微服务名称。也可按照公司规定的规则名命,一目了然。
2.访问信息有IP信息提示
修改8001和8002yml配置:
server: port: 8001 spring: application: name: cloud-payment-service datasource: type: com.alibaba.druid.pool.DruidDataSource driver-class-name: org.gjt.mm.mysql.Driver url: jdbc:mysql://localhost:3306/standarddb?userUnicode=true&characterEncoding=utf-8&useSSL=false username: sa password: HRBJYKJ-Battery mybatis: mapper-locations: classpath:mapper/*.xml type-aliases-package: com.atguigu.springcloud.entities eureka: client: #表示是否将自己注册进EurekaServer,默认true register-with-eureka: true #是否从EurekaServer抓取已有的注册信息,默认为true。单节点无所谓,集群必须设置true才能配合ribbon使用负载均衡。 fetch-registry: true service-url: defaultZone: http://eurreka7001.com:7001/eureka,http://eureka7002.com:7002/eureka #集群版 #主机名实例 instance: instance-id: paymet8001 prefer-ip-address: true #访问路径可以显示IP地址
查看结果: