eureka《一》
注册中心:
@EnableEurekaServer
@SpringBootApplication
public class EureKaMain7001 {
public static void main(String[] args) {
SpringApplication.run(EureKaMain7001.class,args);
}
}
注册中心配置:
server.port=7001 #服务端的示例名称 eureka.instance.hostname=eureka7001.com #不向注册中心注册自己 eureka.client.register-with-eureka=false #自己就是注册中心,职责是维护,并不需要检索服务 eureka.client.fetch-registry=false #这里修改了C:\Windows\System32\drivers\etc\hosts 人为添加了域名 eureka700X.com #集群模式 #eureka.client.service-url.defaultZone=http://eureka7002.com:7002/eureka/ #单机模式 eureka.client.service-url.defaultZone=http://eureka7001.com:7001/eureka/ #自我保护机制默认为true 这里改为false(关闭自我保护) #eureka.server.enable-self-preservation=false #默认60s清理一次过期服务 #eureka.server.eviction-interval-timer-in-ms=2000
服务方配置:
server.port=8001 #链路监控配置 spring.application.name=cloud-payment-server spring.zipkin.base-url=http://localhost:9411 #采样值介于0,1之间 1表示全部采样 spring.sleuth.sampler.probability=1 spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/quanxian?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false&allowPublicKeyRetrieval=true spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.username= spring.datasource.password= #扫描实体类 #扫描xml mybatis.mapperLocations=classpath:mapper/*.xml mybatis.type-aliases-package=atguigu.springcloud.entities #向注册中心注册自己 eureka.client.register-with-eureka=true #自己就是注册中心,并不需要检索服务,单节点无所谓,集群必须设置true,才能使用ribbon负载均衡 eureka.client.fetch-registry=true #注入eureka使用的唯一服务名字(unid) eureka.instance.instance-id=payment8001 #显示IP地址 eureka.instance.prefer-ip-address=true #默认实例每30秒发送一次心跳 #eureka.instance.lease-renewal-interval-in-seconds=1 #注册中心,默认90s内加收到心跳认为服务正常。大于90s认为超时 #eureka.instance.lease-expiration-duration-in-seconds=2 #单机版 eureka.client.service-url.defaultZone=http://localhost:7001/eureka #集群模板 #这里修改了C:\Windows\System32\drivers\etc\hosts 人为添加了域名 eureka700X.com #eureka.client.service-url.defaultZone=http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka
服务方注册启动与发现:
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
public class PaymentMain8001 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8001.class,args);
}
}
消费者配置:
server.port=8080 spring.application.name=cloud-order-consumer-server #向注册中心注册自己 eureka.client.register-with-eureka=true #是否从eureka抓取自己,并不需要检索服务,单节点无所谓,集群必须设置true,才能使用ribbon负载均衡 eureka.client.fetch-registry=true eureka.client.service-url.defaultZone=http://localhost:7001/eureka #集群模板 这里修改了C:\Windows\System32\drivers\etc\hosts 人为添加了域名 eureka7001.com #eureka.client.service-url.defaultZone=http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka eureka.instance.instance-id=cloud-order-consumer-server #显示IP地址 eureka.instance.prefer-ip-address=true
消费者启动配置:
@SpringBootApplication
@EnableEurekaClient
@RibbonClient(name="CLOUD-PAYMENT-SERVER",configuration = MySelfRule.class)//轮询配置
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class,args);
}
}
注入到zk:#集群版逗号分割
spring.cloud.zookeeper.connect-string=xxxxxxxxxx:2181
注入到consul:(有自己的UI界面客户端)
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.service-name=${spring.application.name}
本文来自博客园,作者:余生请多指教ANT,转载请注明原文链接:https://www.cnblogs.com/wangbiaohistory/p/16114772.html

浙公网安备 33010602011771号