Actuator is an additional function in springboot, which contains many other functions. You can choose to use HTTP endpoints or JMX to manage and monitor applications. Auditing, health and metrics collection can also be automatically applied to applications.
What is the core factor in considering whether to use the actuator framework?
During the running of the application, the configuration information of the Apollo server and the local cache of the instance are not always the same.
So I need to know the local configuration data copy of the application accurately through some technical means when I need it, instead of just looking at the server-side data through Apollo protal.
That's why we need actuators!
Let's see what an actuator is.
Spring Boot provides a starter called Spring Boot Starter Actuator.
In the official document, it is introduced like this:
An entry-level product using Spring Boot actuators provides production-ready functions to help you monitor and manage your applications.
In fact, it is not difficult to understand. Let's practice it.
First, define a SchemaEndpoint class. Of course, you must annotate this class with @Endpoint annotation, and you must provide another method to annotate it with @ReadOperation:
@Endpoint(id? =? “schema”)public? Class? SchemaEndpoint? { ? Protected? Apollo conversion factory? Factories; ? Public? schema endpoint(ApolloConverterFactory? Factory) { this.factory? =? Factories; } ? @ReadOperation public? SchemaDescriptor? schema()? {Return? New? schema descriptor(factory . getschemalist(),? factory . get groups()); } ? Public? Static electricity Final? Class? SchemaDescriptor? {Protected? Attribute? schemaList? Protected? Map? Group; ? Public? SchemaDescriptor(@Nullable? Attribute? schemaList,? Map? Group)? { this.schemaList? =? SchemaList, this group? =? Group; } ? @Nullable? Public? Attribute? getSchemaList()? {Return? this.schemaList} ? @Nullable? Public? Map? getGroups()? {Return? this.groups} } }
The ApolloConverterFactory here is a factory class that creates data converters according to the configuration information of Apollo local cache. Its getSchemaList method returns the local cached data of the namespace sec.insight.schema.list, and getGroups returns the list of configuration sets for each group of patterns.
Then, write a configuration class:
@ Configuration @ conditional expression(" $ { Apollo . boostrap . enabled:true }? & amp& amp? $ { spring . Apollo . schema . enabled:true } ")public? Class? apolloschemaconconfiguration? { @Bean public? Apollo conversion factory? apolloConverterFactory()? {Return? New? ApolloConverterFactory(); } ? @ Bean @ ConditionalOnMissingBean @ conditionalonabledendpoint(endpoint? =? SchemaEndpoint.class) public? SchemaEndpoint? schema endpoint(ApolloConverterFactory? Factory) {Return? New? SchemaEndpoint (factory); } }
Finally, just test directly.