具有InlfuxDB的Spring Boot和Micrometer第1部分:基础项目

对于那些关注此博客的人来说,难怪我倾向于大量使用InfluxDB。 我喜欢这样一个事实,它是一个真正的单一用途的数据库(时间序列),具有许多功能,并且还带有企业支持。

Spring也是我选择的工具之一。 因此,在本博客中,我们将把spring与micrometer和InfluxDB集成在一起。

我们的应用程序将是用于工作的rest api。 最初,它会从GitHub的工作API如图所示取乔布斯在这里

让我们从pom开始

 <?xml version= "1.0" encoding= "UTF-8" ?>  <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 " > 
     <modelVersion> 4.0 . 0 </modelVersion> 
     <parent> 
         <groupId>org.springframework.boot</groupId> 
         <artifactId>spring-boot-starter-parent</artifactId> 
         <version> 2.2 . 4 .RELEASE</version> 
     </parent> 
     <groupId>com.gkatzioura</groupId> 
     <artifactId>DevJobsApi</artifactId> 
     <version> 1.0 -SNAPSHOT</version> 
     <build> 
         <defaultGoal>spring-boot:run</defaultGoal> 
         <plugins> 
             <plugin> 
                 <groupId>org.apache.maven.plugins</groupId> 
                 <artifactId>maven-compiler-plugin</artifactId> 
                 <configuration> 
                     <source> 8 </source> 
                     <target> 8 </target> 
                 </configuration> 
             </plugin> 
             <plugin> 
                 <groupId>org.springframework.boot</groupId> 
                 <artifactId>spring-boot-maven-plugin</artifactId> 
             </plugin> 
         </plugins> 
     </build> 
     <dependencies> 
         <dependency> 
             <groupId>org.springframework.boot</groupId> 
             <artifactId>spring-boot-starter-webflux</artifactId> 
         </dependency> 
         <dependency> 
             <groupId>org.projectlombok</groupId> 
             <artifactId>lombok</artifactId> 
             <version> 1.18 . 12 </version> 
             <scope>provided</scope> 
         </dependency> 
    </dependencies>  </project> 

让我们为GitHub添加Job Repository。

 package com.gkatzioura.jobs.repository;  import java.util.List;  import org.springframework.http.HttpMethod;  import org.springframework.stereotype.Repository;  import org.springframework.web.reactive.function.client.WebClient;  import com.gkatzioura.jobs.model.Job;  import reactor.core.publisher.Mono;  @Repository  public class GitHubJobRepository { 
     private WebClient githubClient; 
     public GitHubJobRepository() { 
         this .githubClient = WebClient.create( " https://jobs.github.com " ); 
     } 
     public Mono<List<Job>> getJobsFromPage( int page) { 
         return githubClient.method(HttpMethod.GET) 
                            .uri( "/positions.json?page=" + page) 
                            .retrieve() 
                            .bodyToFlux(Job. class ) 
                            .collectList(); 
     }  } 

工作模式

 package com.gkatzioura.jobs.model;  import lombok.Data;  @Data  public class Job { 
     private String id; 
     private String type; 
     private String url; 
     private String createdAt; 
     private String company; 
     private String companyUrl; 
     private String location; 
     private String title; 
     private String description;  } 

控制器

 package com.gkatzioura.jobs.controller;  import java.util.List;  import org.springframework.web.bind.annotation.GetMapping;  import org.springframework.web.bind.annotation.PathVariable;  import org.springframework.web.bind.annotation.RequestMapping;  import org.springframework.web.bind.annotation.RestController;  import com.gkatzioura.jobs.model.Job;  import com.gkatzioura.jobs.repository.GitHubJobRepository;  import reactor.core.publisher.Mono;  @RestController  @RequestMapping ( "/jobs" )  public class JobsController { 
     private final GitHubJobRepository gitHubJobRepository; 
     public JobsController(GitHubJobRepository gitHubJobRepository) { 
         this .gitHubJobRepository = gitHubJobRepository; 
     } 
     @GetMapping ( "/github/{page}" ) 
     private Mono<List<Job>> getEmployeeById( @PathVariable int page) { 
         return gitHubJobRepository.getJobsFromPage(page); 
     }  } 

最后但并非最不重要的主要应用程序。

 com.gkatzioura; package com.gkatzioura;  import org.springframework.boot.SpringApplication;  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  import org.springframework.boot.autoconfigure.SpringBootApplication;  import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration;  @SpringBootApplication  @EnableAutoConfiguration (exclude = { 
         ReactiveSecurityAutoConfiguration. class  })  public class Application { 
     public static void main(String[] args) { 
         SpringApplication.run(Application. class , args); 
     }  } 

在下一个博客中,我们将与InfluxDB和测微仪集成。

翻译自: https://www.javacodegeeks.com/2020/02/spring-boot-and-micrometer-with-inlfuxdb-part-1-the-base-project.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值