java -version
<dependency><groupId>com.tencentcloudapi.cls</groupId><artifactId>tencentcloud-cls-sdk-java</artifactId><version>1.0.15</version></dependency>
Variable | Type | Required | Description |
endpoint | String | Yes | Domain information, please refer to the domain name in the available region under the Log upload via API Tab. |
secretId | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
secretKey | String | Yes | TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission. |
topicId | String | Yes | Log topic ID info. |
import com.tencentcloudapi.cls.sdk.AsyncProducerClient;import com.tencentcloudapi.cls.sdk.AsyncProducerConfig;import com.tencentcloudapi.cls.sdk.LogItem;import com.tencentcloudapi.cls.sdk.LogContent;import com.tencentcloudapi.cls.sdk.NetworkUtils;import java.util.ArrayList;import java.util.List;public class TencentClsDemo {public static void main(String[] args) {// Fill in the domain information, see the domain name in the Log upload via API Tab: https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8DString endpoint = "ap-xxxxxx.cls.tencentcs.com";// Fill in the cloud API Key Information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi// Please ensure the associated account has appropriate log upload permissions. For the permission configuration guide, see: https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE// This example retrieves from environmental variable. For environment variable configuration guide, see: https://www.tencentcloud.com/document/product/614/113851?from_cn_redirect=1String secretId = System.getenv("TENCENTCLOUD_SECRET_ID");String secretKey = System.getenv("TENCENTCLOUD_SECRET_KEY");// fill in the log topic IDString topicId = "5912XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";final AsyncProducerConfig config = new AsyncProducerConfig(endpoint, secretId, secretKey, NetworkUtils.getLocalMachineIP());// Build a client instance.final AsyncProducerClient client = new AsyncProducerClient(config);for (int i = 0; i < 10000; ++i) {List<LogItem> logItems = new ArrayList<>();int ts = (int) (System.currentTimeMillis() / 1000);LogItem logItem = new LogItem(ts);logItem.PushBack(new LogContent("__CONTENT__", "hello world"));logItem.PushBack(new LogContent("city", "guangXXXXX"));logItem.PushBack(new LogContent("logNo", Integer.toString(i)));logItem.PushBack(new LogContent("__PKG_LOGID__", (String.valueOf(System.currentTimeMillis()))));logItems.add(logItem);client.putLogs(topicId, logItems, result -> System.out.println(result.toString()));}client.close();}}
Feedback