DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Trending

  • Agentic AI Has an Observability Blind Spot Nobody Is Talking About
  • Advanced Error Handling and Retry Patterns in Enterprise REST Integrations
  • From "Vibe Coding" to Production: Setting Up an Evals Loop for Claude Agents
  • The Documentation Crisis Nobody Sees: Why AI Agents Are Breaking Faster Than Humans Can Document Them
  1. DZone
  2. Coding
  3. Frameworks
  4. Spring Boot and Micrometer With InlfuxDB Part 1: The Base Project

Spring Boot and Micrometer With InlfuxDB Part 1: The Base Project

In this article, take a look at how to integrate Spring with Micrometer and InfluxDB.

By 
Emmanouil Gkatziouras user avatar
Emmanouil Gkatziouras
DZone Core CORE ·
Nov. 23, 20 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
9.3K Views

Join the DZone community and get the full member experience.

Join For Free

To those who follow this blog, it’s no wonder that I tend to use InfluxDB a lot. I like the fact that it is a real single purpose database (time series) with many features and also comes with enterprise support.

Spring is also one of the tools of my choice.
Thus in this blog, we shall integrate Spring with Micrometer and InfluxDB.

Our application will be a RET API for jobs.
Initially, it will fetch the Jobs from GitHub’s job API as shown here.

Let’s start with a pom

XML
 




x
45


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
    <modelVersion>4.0.0</modelVersion>
4
 
5
    <parent>
6
        <groupId>org.springframework.boot</groupId>
7
        <artifactId>spring-boot-starter-parent</artifactId>
8
        <version>2.2.4.RELEASE</version>
9
    </parent>
10
 
11
    <groupId>com.gkatzioura</groupId>
12
    <artifactId>DevJobsApi</artifactId>
13
    <version>1.0-SNAPSHOT</version>
14
 
15
    <build>
16
        <defaultGoal>spring-boot:run</defaultGoal>
17
        <plugins>
18
            <plugin>
19
                <groupId>org.apache.maven.plugins</groupId>
20
                <artifactId>maven-compiler-plugin</artifactId>
21
                <configuration>
22
                    <source>8</source>
23
                    <target>8</target>
24
                </configuration>
25
            </plugin>
26
            <plugin>
27
                <groupId>org.springframework.boot</groupId>
28
                <artifactId>spring-boot-maven-plugin</artifactId>
29
            </plugin>
30
        </plugins>
31
    </build>
32
 
33
    <dependencies>
34
        <dependency>
35
            <groupId>org.springframework.boot</groupId>
36
            <artifactId>spring-boot-starter-webflux</artifactId>
37
        </dependency>
38
        <dependency>
39
            <groupId>org.projectlombok</groupId>
40
            <artifactId>lombok</artifactId>
41
            <version>1.18.12</version>
42
            <scope>provided</scope>
43
        </dependency>
44
   </dependencies>
45
</project>


Let’s add the Job Repository for GitHub.

Java
 




xxxxxxxxxx
1
32


 
1
package com.gkatzioura.jobs.repository;
2
 
3
import java.util.List;
4
 
5
import org.springframework.http.HttpMethod;
6
import org.springframework.stereotype.Repository;
7
import org.springframework.web.reactive.function.client.WebClient;
8
 
9
import com.gkatzioura.jobs.model.Job;
10
 
11
import reactor.core.publisher.Mono;
12
 
13
@Repository
14
public class GitHubJobRepository {
15
 
16
    private WebClient githubClient;
17
 
18
    public GitHubJobRepository() {
19
        this.githubClient = WebClient.create("https://jobs.github.com");
20
    }
21
 
22
    public Mono<List<Job>> getJobsFromPage(int page) {
23
 
24
        return githubClient.method(HttpMethod.GET)
25
                           .uri("/positions.json?page=" + page)
26
                           .retrieve()
27
                           .bodyToFlux(Job.class)
28
                           .collectList();
29
    }
30
 
31
}
32

          


The Job model

Java
 




xxxxxxxxxx
1
18


 
1
package com.gkatzioura.jobs.model;
2
 
3
import lombok.Data;
4
 
5
@Data
6
public class Job {
7
 
8
    private String id;
9
    private String type;
10
    private String url;
11
    private String createdAt;
12
    private String company;
13
    private String companyUrl;
14
    private String location;
15
    private String title;
16
    private String description;
17
 
18
}


The controller

Java
 




xxxxxxxxxx
1
30


 
1
package com.gkatzioura.jobs.controller;
2
 
3
import java.util.List;
4
 
5
import org.springframework.web.bind.annotation.GetMapping;
6
import org.springframework.web.bind.annotation.PathVariable;
7
import org.springframework.web.bind.annotation.RequestMapping;
8
import org.springframework.web.bind.annotation.RestController;
9
 
10
import com.gkatzioura.jobs.model.Job;
11
import com.gkatzioura.jobs.repository.GitHubJobRepository;
12
 
13
import reactor.core.publisher.Mono;
14
 
15
@RestController
16
@RequestMapping("/jobs")
17
public class JobsController {
18
 
19
    private final GitHubJobRepository gitHubJobRepository;
20
 
21
    public JobsController(GitHubJobRepository gitHubJobRepository) {
22
        this.gitHubJobRepository = gitHubJobRepository;
23
    }
24
 
25
    @GetMapping("/github/{page}")
26
    private Mono<List<Job>> getEmployeeById(@PathVariable int page) {
27
        return gitHubJobRepository.getJobsFromPage(page);
28
    }
29
 
30
}


And last but not least the main application.

Java
 




xxxxxxxxxx
1
18


 
1
package com.gkatzioura;
2
 
3
 
4
import org.springframework.boot.SpringApplication;
5
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
6
import org.springframework.boot.autoconfigure.SpringBootApplication;
7
import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration;
8
 
9
@SpringBootApplication
10
@EnableAutoConfiguration(exclude = {
11
        ReactiveSecurityAutoConfiguration.class
12
})
13
public class Application {
14
 
15
    public static void main(String[] args) {
16
        SpringApplication.run(Application.class, args);
17
    }
18
}


On the next blog, we are going to integrate with InfluxDB and micrometer.

Spring Framework Spring Boot

Published at DZone with permission of Emmanouil Gkatziouras. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project
  • A Practical Guide to Creating a Spring Modulith Project
  • Structured Logging in Spring Boot 3.4 for Improved Logs

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook