当前位置:网站首页>Eureka console accesses the info endpoint exposed by the microservice
Eureka console accesses the info endpoint exposed by the microservice
2022-06-21 21:54:00 【crysw】
1. brief introduction
I'm learning Eureka In the process , Find out Eureka In the list of microservice instances registered on the console , The microservice address can be accessed by clicking info Endpoint , But it will jump to SpringBoot The default exception information interface , This is because microservices are not exposed info Endpoint . Next is Eureka Instance naming and info End point information access gives a case .
2. Build microservices
2.1 Microservice design
Here, the process of setting up a micro service is omitted , I created three microservices :
eureka Micro service registration center : microservicecloud-eureka
Microservice providers : microservicecloud-provider
Micro service consumers : microservicecloud-consumer
2.2 Micro service configuration information
2.2.1 eureka Registry Center To configure
Stand alone configuration
server:
port: 7001
eureka:
instance:
hostname: localhost # Eureka The instance name of the server
client:
# Whether to register to Eureka Service center
register-with-eureka: false
# Whether from Eureka The service center obtains the registered service instance
fetch-registry: false
service-url:
defaultZone: http://${
eureka.instance.hostname}:${
server.port}/eureka
server:
enable-self-preservation: true # Self-protection mechanism
2.2.2 Microservice providers To configure
server:
port: 8002
spring:
application:
name: microservicecloud-provider
# eureka client
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka # Eureka Address of Registration Center
2.2.3 Micro service consumers To configure
server:
port: 8080
spring:
application:
name: microservicecloud-consumer
# Eureka Client configuration
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
2.2.4 Start microservices
Start the above three microservices , visit http://localhost:7001/, see Eureka Microservice registration list of the console .
From the picture above , We can see the name of the microservice instance , Address , Port and other information , But the host name is shown wang_qz, If there are many servers in the production environment , Host names are not identifiable , If you want to show specific ip Address , Configure... As follows .
stay Eureka client Microservice configuration ( service provider or Service consumer )
# Eureka Client configuration
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka
instance:
instance-id: microservicecloud-consumer-01 # Configure the name of the microservice registration
prefer-ip-address: true # priority of use ip register , Access display ip
start-up Microservice providers , Revisit http://localhost:7001/, see Eureka Console Registration list :
3. visit info Endpoint
3.1 reform Service consumer
Click on microservicecloud-consumer-01, visit http://192.168.43.191:8080/actuator/info, 192.168.43.191 It's my host address , The result is an error message interface .
This is because there is no exposure info Endpoint Give external access to , You need to add startup dependencies that expose endpoints :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Configure exposed info Endpoint Information
# Exposed end point info
info:
app.name: microservicecloud-consumer
company.name: www.atguigu.com
build.artifactId: com.atguigu.springcloud
build.version: 1.0-SNAPSHOT
restart Microservice providers , Revisit http://localhost:7001/, see Eureka Console For the registration list, click microservicecloud-consumer-01 visit http://192.168.43.191:8080/actuator/info, It is found that... Has been accessed normally info Endpoint information .
3.2 reform service provider
above Service consumer Of info The endpoint has passed Eureka Click the link to access the registration center successfully , however info Endpoint The information is written in the configuration file , If the project name or version changes , The configuration file also needs to be modified synchronously , have access to ${} Placeholder to get project information .
First , Add the same actuator Start dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Add exposed info Endpoint Information
# eureka client
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka # Eureka Address of Registration Center
instance:
instance-id: microservicecloud-provider-02 # Custom microservice name information
prefer-ip-address: true # priority of use id register , The access path can be displayed IP Address
# exposed info Endpoint information
info:
app.name: ${
spring.application.name}
company.name: www.atguigu.com
build.artifactId: ${
project.artifactId}
restart service provider , visit http://localhost:7001/, see Eureka Console List of Registry Services .
Click on microservicecloud-provider-02 , visit http://192.168.43.191:8002/actuator/info, I found the wrong report , Why ?
Let's check the error log , The discovery cannot be resolved ${} Placeholder to get the attribute value .
resolvent , Building pom Add build to build , Specify resolution $ Symbol .
<!-- structure , Packaging plug-in -->
<build>
<finalName>microservicecloud</finalName>
<resources>
<resource>
<!-- Specify the resource file location -->
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<delimiters>
<!-- Able to parse src/main/resources/ In the configuration file $ Placeholder to get property value ; -->
<!--Eureka Click on the service list to access the exposed endpoint information of the specified microservice -->
<delimit>$</delimit>
</delimiters>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
restart service provider , visit http://localhost:7001/, see Eureka Console List of Registry Services .
Click on microservicecloud-provider-02 , visit http://192.168.43.191:8002/actuator/info, info The normal parsing of information returns .
4. summary
Access to microservices info Endpoint Information , Here are some points :
<1> add to
actuatorStart dependency , Exposed end point .
<2> Profile addinfo Endpoint information.
<3> If info Endpoint information uses${}Placeholder to get property value , Need to build pom Specify the resolution in the file$Symbol configuration .
Personal blog
Welcome to my personal blog : https://www.crystalblog.xyz/
Alternate address : https://wang-qz.gitee.io/crystal-blog/
边栏推荐
- Qx2308 high efficiency PFM Synchronous Boost dc/dc converter
- LeetCode508-出现次数最多的子树元素和-深搜
- Jerry's problem of playing songs after opening four channel EQ [chapter]
- prototype扩展:实现对象继承
- 撰写学术论文引用文献时,标准的格式是怎样的?
- With what to save you? My attention
- In the anchoring stage of retail digitalization, more attention is paid to how to mine and transform traffic by means of Digitalization
- Go语言单元测试模拟服务请求和接口返回
- 杰理之获取当前音频文件(长)文件名和当前(长)文件夹名【篇】
- ACM. Hj61 put apple ●
猜你喜欢

js中的for.....in函数

中微半导体通过注册:年营收11亿 实控人为新西兰国籍

Ln2220 2A overcurrent 5v1a High Efficiency Boost IC chip dc/dc voltage regulator

How to search foreign literature efficiently?

Scientific research cartoon | you can learn EEG by looking at the picture. Would you like to try it?

solidity实现智能合约教程(4)-ERC1155合约

InteliJ-IDEA-高效技巧(二)

Delaying patient self-help guide | "I have 100 excuses for not delaying, but I am not willing to take a step"

Database management: Navicat premium 15

AWS CloudWatch
随机推荐
For in JS In function
Tx9116 Synchronous Boost IC
晶合集成通过注册:拟募资95亿 合肥建投与美的是股东
AWS CloudWatch
When Jerry made Bluetooth transmission, when he modified stereo to mono differential output, there was a jam sound at the receiving end [chapter]
Yanyu saltalk obtained USD 8million round a financing: continue to expand team and market coverage
K - Clairewd’s message HDU - 4300 (EXKMP)
Go unit test mocks the database CRUD
C language array and pointer exercises (original question + analysis + original code)
Mendeley installation, configuration and use
Cocoapods installation (after xcode8.0, the infinite card is in the setting up cocoapods master repo)
Jerry wants to keep both earphones output stereo after pairing them [chapter]
ADT Spec RI AF CheckRep Safety from Rep Exposure
JS object operation (much simpler than C object)
Operation of 2022 welder (Advanced) examination question bank simulation examination platform
3D octave view
MySQL创建表时的条件有哪些
Can I open an account for online stock trading? Is it safe
C语言数组与指针练习题(原题+解析+原码)
What is EGFP, green fluorescent protein