openGemini Spring Integrations provide seamless integration between the openGemini client and Spring applications. This project offers both synchronous and asynchronous configurations tailored to different Spring environments.
This project includes three primary modules:
- opengemini-spring: Core integration module for Spring applications.
- opengemini-spring-boot-starter: Synchronous starter for Spring WebMVC.
- opengemini-spring-boot-starter-reactive: Asynchronous starter for Spring WebFlux.
- SpringBoot auto configuration support for an OpenGeminiTemplate/ReactiveOpenGeminiTemplate instance.
OpenGeminiTemplate/ReactiveOpenGeminiTemplateclass that increases productivity performing common openGemini operations. Includes integrated object mapping between points and POJOs.- Annotation based mapping metadata.
- Support create database and retention policy automatically.
This project requires JDK 17 or later and supports Spring 6 and Spring Boot 3.
Below is a brief example demonstrating how to use the OpenGemini Spring Boot Starter in a Java application.
Add the following dependency to your project's pom.xml:
<dependency>
<groupId>io.opengemini</groupId>
<artifactId>opengemini-spring-boot-starter</artifactId>
<version>${version}</version>
</dependency>Following properties can be used in your application.yaml:
spring:
opengemini:
addresses: localhost:8086@Database(name = "test_db", create = false)
@RetentionPolicy(name = "test_rp", create = false)
@Measurement(name = "test_ms")
public class Weather {
@Tag(name = "Location")
private String location;
@Field(name = "Temperature")
private Double temperature;
@Time(precision = Precision.PRECISIONMILLISECOND)
private Long time;
}@Service
public class WeatherService {
private final OpenGeminiTemplate template;
public WeatherService(OpenGeminiTemplate template) {
this.template = template;
}
public void doWork() {
Weather weather = new Weather();
weather.setLocation("shenzhen");
weather.setTemperature(30.5D);
weather.setTime(System.currentTimeMillis());
MeasurementOperations<Weather> operations = template.opsForMeasurement(Weather.class);
operations.write(weather);
Query query = new Query("SELECT * FROM \"test_ms\" limit 1");
List<Weather> results = operations.query(query);
}
}