日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

acm java_ACM Java Native SDK 概述

發布時間:2025/3/20 java 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 acm java_ACM Java Native SDK 概述 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

示例代碼

添加依賴后,即可在程序中使用 ACM Java Native SDK 提供的接口。

說明 請將代碼中的 $regionId、$endpoint、$namespace、$accessKey、$secretKey 分別替換為 ACM 控制臺上命名空間詳情對話框內的地域 ID、End Point、命名空間 ID、AccessKey、SecretKey。

import java.util.Properties;

import com.alibaba.edas.acm.ConfigService;

import com.alibaba.edas.acm.exception.ConfigException;

import com.alibaba.edas.acm.listener.ConfigChangeListener;

import com.alibaba.edas.acm.listener.PropertiesListener;

// 示例代碼,僅用于示例測試

public class ACMTest {

// 屬性/開關

private static String config = "DefaultValue";

private static Properties acmProperties = new Properties();

public static void main(String[] args) {

try {

// 從控制臺命名空間管理中拷貝對應值

Properties properties = new Properties();

properties.put("endpoint", "$endpoint");

properties.put("namespace", "$namespace");

// 通過 ECS 實例 RAM 角色訪問 ACM

// properties.put("ramRoleName", "$ramRoleName");

properties.put("accessKey", "$accessKey");

properties.put("secretKey", "$secretKey");

// 如果是加密配置,則添加下面兩行進行自動解密

//properties.put("openKMSFilter", true);

//properties.put("regionId", "$regionId");

ConfigService.init(properties);

// 主動獲取配置

String content = ConfigService.getConfig("${dataId}", "${group}", 6000);

System.out.println(content);

// 初始化的時候,給配置添加監聽,配置變更會回調通知

ConfigService.addListener("${dataId}", "${group}", new ConfigChangeListener() {

public void receiveConfigInfo(String configInfo) {

// 當配置更新后,通過該回調函數將最新值返回給用戶。

// 注意回調函數中不要做阻塞操作,否則阻塞通知線程。

config = configInfo;

System.out.println(configInfo);

}

});

/**

* 如果配置值的內容為properties格式(key=value),可使用下面監聽器。以便一個配置管理多個配置項

*/

/**

ConfigService.addListener("${dataId}", "${group}", new PropertiesListener() {

@Override

public void innerReceive(Properties properties) {

// TODO Auto-generated method stub

acmProperties = properties;

System.out.println(properties);

}

});

**/

} catch (ConfigException e) {

e.printStackTrace();

}

// 測試讓主線程不退出,因為訂閱配置是守護線程,主線程退出守護線程就會退出。 正式代碼中無需下面代碼

while (true) {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

// 通過get接口把配置值暴露出去使用

public static String getConfig() {

return config;

}

// 通過get接口把配置值暴露出去使用

public static Object getPorpertiesValue(String key) {

if (acmProperties != null) {

return acmProperties.get(key);

}

return null;

}

}

總結

以上是生活随笔為你收集整理的acm java_ACM Java Native SDK 概述的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。