79 lines
2.8 KiB
Java
79 lines
2.8 KiB
Java
|
package com.cnbm.influx.controller;
|
||
|
|
||
|
import com.cnbm.influx.config.InfluxClient;
|
||
|
import com.cnbm.influx.template.Event;
|
||
|
import com.influxdb.client.InfluxDBClient;
|
||
|
import com.influxdb.client.domain.WritePrecision;
|
||
|
import com.influxdb.client.write.Point;
|
||
|
import org.slf4j.Logger;
|
||
|
import org.slf4j.LoggerFactory;
|
||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
import org.springframework.web.bind.annotation.RestController;
|
||
|
import java.time.Instant;
|
||
|
|
||
|
@RestController
|
||
|
@RequestMapping("/influx")
|
||
|
public class S7DemoController {
|
||
|
private static final Logger logger = LoggerFactory.getLogger(S7DemoController.class);
|
||
|
|
||
|
@Autowired
|
||
|
InfluxDBClient influxDBClient;
|
||
|
|
||
|
|
||
|
// try (WriteApi writeApi = influxDBClient.makeWriteApi()) {
|
||
|
// Temperature temperature = new Temperature();
|
||
|
// temperature.setLocation("east");
|
||
|
// temperature.setValue(106.2D);
|
||
|
// temperature.setTime(Instant.now());
|
||
|
// writeApi.writeMeasurement(WritePrecision.NS,temperature);
|
||
|
// }
|
||
|
//
|
||
|
// try (WriteApi writeApi = influxDBClient.makeWriteApi()) {
|
||
|
// Point point = Point.measurement("temperature")
|
||
|
// .addTag("location","south")
|
||
|
// .addTag("owner","wxm")
|
||
|
// .addField("wxm",230.8);
|
||
|
// writeApi.writePoint(point);
|
||
|
// }
|
||
|
|
||
|
|
||
|
@PostMapping("/insertBatch")
|
||
|
public void insertBatch() throws InterruptedException {
|
||
|
// List<Event> list = new ArrayList<>();
|
||
|
//
|
||
|
// for(int i=0;i<99;i++){
|
||
|
// //Thread.sleep(1000);
|
||
|
// Event event = new Event();
|
||
|
// event.time = Instant.now();
|
||
|
// event.transationId = "asas"+i;
|
||
|
// event.argName = "arg5";
|
||
|
// event.argValue = new Double(i);
|
||
|
// list.add(event);
|
||
|
// }
|
||
|
// influxService.batchInsert(list);
|
||
|
}
|
||
|
|
||
|
|
||
|
public Point insert(Event event, String measurement){
|
||
|
Point point = Point.measurement(measurement)
|
||
|
.addTag("transationId", event.getTransationId())
|
||
|
.addTag("argName", event.getArgName())
|
||
|
.addField("argValue", event.getArgValue())
|
||
|
.time(event.getTime().toEpochMilli(), WritePrecision.MS);
|
||
|
return point;
|
||
|
|
||
|
}
|
||
|
@PostMapping("/insert")
|
||
|
public void insert() throws InterruptedException {
|
||
|
Event event = new Event();
|
||
|
event.setTime(Instant.now());
|
||
|
event.setTransationId("asasd11");
|
||
|
event.setArgName("argName11");
|
||
|
event.setArgValue(7d);
|
||
|
Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
|
||
|
influxDBClient.makeWriteApi().writePoint(asProcessCompleteEvent);
|
||
|
}
|
||
|
}
|