java,actuator
<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
java actuator是什麼,讓我們一起了解一下?
actuator是springboot中的一個附加功能,SpringBoot包含了許多其他特性,可以選擇使用HTTP端點或使用JMX來管理和監視應用程序。審計、健康和度量收集也可以自動應用於應用程序。
考慮是否使用actuator框架的核心因素是什麼?
在應用運行過程中,Apollo服務器端的配置信息和實例本地緩存的配置信息並不是時時刻刻都相同的。
因此,我需要能夠通過某種技術手段,可以在需要時準確獲知應用本地的配置數據副本,而不是僅能通過Apollo的protal查看服務器端數據。
這就需要actuator的原因!
讓我們來看看actuator具體是什麼。
Spring Boot提供了名稱爲spring-boot-starter-actuator的starters。
在官方文檔中是這樣介紹的:
Starter for using Spring Boot’s Actuator which provides production ready features to help you monitor and manage your application
其實也不難理解,讓我們實戰操作一下。
首先,定義一個SchemaEndpoint類。當然,得用@Endpoint註解來標註這個類,還要再提供一個使用@ReadOperation標註的方法:
@Endpoint(id = "schema")public class SchemaEndpoint { protected ApolloConverterFactory factory; public SchemaEndpoint(ApolloConverterFactory factory) { this.factory = factory; } @ReadOperation public SchemaDescriptor schema() { return new SchemaDescriptor(factory.getSchemaList(), factory.getGroups()); } public static final class SchemaDescriptor { protected Properties schemaList; protected Map<String, Properties> groups; public SchemaDescriptor(@Nullable Properties schemaList, Map<String, Properties> groups) { this.schemaList = schemaList; this.groups = groups; } @Nullable public Properties getSchemaList() { return this.schemaList; } @Nullable public Map<String, Properties> getGroups() { return this.groups; } }}
這裏面的ApolloConverterFactory是基於Apollo本地緩存的配置信息創建數據轉換器的工廠類。它的getSchemaList方法,返回的是sec.insight.schema.list這個namespace的本地緩存數據,getGroups返回的是每一組schema的配置集合清單。
然後,再來編寫一個配置類:
@Configuration@ConditionalOnExpression("${apollo.boostrap.enabled:true} && ${spring.apollo.schema.enabled:true}")public class ApolloSchemaConfiguration { @Bean public ApolloConverterFactory apolloConverterFactory() { return new ApolloConverterFactory(); } @Bean @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint(endpoint = SchemaEndpoint.class) public SchemaEndpoint schemaEndpoint(ApolloConverterFactory factory) { return new SchemaEndpoint(factory); }}
最後直接測試就可以了。
-
百度網盤如何註冊登錄
百度網盤是百度推出的一項雲存儲服務,可以大容量的儲存文件視頻等,那百度網盤怎麼註冊登錄呢?一起來看看吧!首先,在手機桌面上找到並打開百度網盤軟件,會看到有百度賬號登錄、微信快捷登錄、微博、qq和手機號註冊幾個登錄方式,點擊手機號註冊;頁面加載至註冊頁面,輸入手...
-
怎樣驅除蚊子
被蚊子咬不但很難受,而且蚊子還會傳染疾病,那麼驅除蚊子的方法有哪些呢?一起來看看吧。首先要讓蚊子不願意靠近你,白天出門時可以在身上塗上能驅除蚊子的產品,在暴露的皮膚或者衣物上使用驅蚊劑。如果你白天出門會使用防曬霜,在塗抹防曬霜之後再使用驅蚊劑。部分驅蚊...
-
超話等級在哪看
1、首先打開微博app,在首頁點擊我的選項,然後進入自己關注的超話,這時可以點擊超話頭像旁顯示的粉絲數,點擊進入之後就可以看到我的等級了。2、微博超話指的是微博的超級話題,是在新浪微博裏面的興趣內容社區。它是將話題模式和社區屬性相結合的產品,目前微博超話的...
-
美圖秀秀手機怎麼縮小圖片大小
美圖秀秀是一款很受歡迎的修圖軟件,很多人都喜歡用美圖秀秀來對圖片進行處理,但美圖秀秀不能對圖片的大小進行隨意修改,那麼,手機美圖秀秀要怎麼縮小圖片呢?首先我們將手機美圖秀秀打開,在首頁點擊【圖片美化】功能按鈕,然後可以打開選擇相冊界面,找到需要修改的圖片,點...