springcloud-05-ribbon中不使用eureka
生活随笔
收集整理的這篇文章主要介紹了
springcloud-05-ribbon中不使用eureka
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ribbon在有eureka的情況下, 可以不使用eureka, 挺簡(jiǎn)單, 直接上代碼
application.xml
server:port: 7002 spring:# 設(shè)置eureka中注冊(cè)的名稱, 全小寫(xiě), 否則大小寫(xiě)混雜出現(xiàn)問(wèn)題application:name: microservice-consumer-movie-ribben-ymllogging:level:root: INFOorg.hibernate: INFOorg.hibernate.type.descriptor.sql.BasicBinder: TRACEorg.hibernate.type.descriptor.sql.BasicExtractor: TRACEcom.itmuch: DEBUG eureka:client:serviceUrl:defaultZone: http://wenbronk:abc@localhost:8761/eureka # 添加注冊(cè)中心中的ip代替主機(jī)名instance:prefer-ip-c: trueinstance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}statusPageUrlPath: ${management.context-path}/infohealthCheckUrlPath: ${management.context-path}/health# 在ribbon中禁用eureka ribbon:eureka:enabled: false# 自定義ribbonclient, 不使用eureka, 使用這個(gè)配置 microservice-provider-user:ribbon:listOfServers: localhost:79012, MovieController中使用此方法測(cè)試:
@RequestMapping("/movie/{id}")public User findById(@PathVariable Long id) {ServiceInstance instance = this.loadBalancerClient.choose("microservice-provider-user");URI storesUri = URI.create(String.format("http://%s:%s", instance.getHost(), instance.getPort()));System.out.println("111: " + instance.getServiceId() + ": " + instance.getHost() + ": " + instance.getPort());return null; // return restTemplate.getForObject("http://microservice-provider-user/simple/" + id, User.class);}客戶端發(fā)起請(qǐng)求后 , 可看到日志里面只有 7901 端口在被訪問(wèn), 注釋掉yml中的最后2項(xiàng)配置, 就可以看到eureka默認(rèn)的輪詢配置
?
總結(jié)
以上是生活随笔為你收集整理的springcloud-05-ribbon中不使用eureka的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 女人梦到死鸡什么预兆吗
- 下一篇: 只能输入正整数 以及常用的正则表达式