package com.volcengine.example.tls.demo;
import com.volcengine.model.tls.LogItem;
import com.volcengine.model.tls.exception.LogException;
import com.volcengine.model.tls.producer.CallBack;
import com.volcengine.model.tls.producer.ProducerConfig;
import com.volcengine.model.tls.producer.Result;
import com.volcengine.service.tls.Producer;
import com.volcengine.service.tls.ProducerImpl;
import java.util.ArrayList;
public static void main(String[] args) throws LogException, InterruptedException {
ProducerConfig producerConfig = new ProducerConfig(System.getenv("VOLCENGINE_ENDPOINT"), System.getenv("VOLCENGINE_REGION"),
System.getenv("VOLCENGINE_ACCESS_KEY_ID"), System.getenv("VOLCENGINE_ACCESS_KEY_SECRET"), System.getenv("VOLCENGINE_TOKEN"));
Producer producer = new ProducerImpl(producerConfig);
String topicID = "your-topic-id";
String source = "your-log-source";
String filename = "your-log-filename";
CallBack callBack = new CallBack() {
public void onComplete(Result result) {
System.out.println("producer result:" + result);
item.setTime(System.currentTimeMillis());
item.addContent("key1", "value1");
item.addContent("key2", "value2");
producer.sendLogV2("", topicID, source, filename, item, callBack);
List<LogItem> items = new ArrayList<>();
for (int i = 1; i <= 1000; i++) {
item.setTime(System.currentTimeMillis());
item.addContent("key1", "value1-" + i);
item.addContent("key2", "value2-" + i);
producer.sendLogsV2("", topicID, source, filename, items, callBack);