Skip to content

Commit eb9dbbf

Browse files
committed
添加ApiBoot Sequence示例项目
1 parent 04b8d1e commit eb9dbbf

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>api-boot-samples</artifactId>
7+
<groupId>org.minbox.framework</groupId>
8+
<version>${revision}</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>api-boot-sample-sequence</artifactId>
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-web</artifactId>
17+
</dependency>
18+
<!--ApiBoot Sequence依赖-->
19+
<dependency>
20+
<groupId>org.minbox.framework</groupId>
21+
<artifactId>api-boot-starter-sequence</artifactId>
22+
</dependency>
23+
</dependencies>
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.minbox.framework</groupId>
28+
<artifactId>api-boot-dependencies</artifactId>
29+
<version>${api-boot.version}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
</dependencies>
34+
</dependencyManagement>
35+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.minbox.framework.api.boot.sample;
2+
3+
import org.minbox.framework.api.boot.autoconfigure.sequence.ApiBootSequenceContext;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.CommandLineRunner;
8+
import org.springframework.boot.SpringApplication;
9+
import org.springframework.boot.autoconfigure.SpringBootApplication;
10+
11+
/**
12+
* @author 恒宇少年
13+
*/
14+
@SpringBootApplication
15+
public class ApiBootSequenceSampleApplication implements CommandLineRunner {
16+
/**
17+
* logger instance
18+
*/
19+
static Logger logger = LoggerFactory.getLogger(ApiBootSequenceSampleApplication.class);
20+
21+
public static void main(String[] args) {
22+
SpringApplication.run(ApiBootSequenceSampleApplication.class, args);
23+
logger.info("服务启动成功.");
24+
}
25+
26+
/**
27+
* 注入ApiBoot提供的分布式ID生成类
28+
* <p>
29+
* 调用{@link ApiBootSequenceContext#nextId()}、{@link ApiBootSequenceContext#nextStringId()}方法可以直接获取ID
30+
*/
31+
@Autowired
32+
private ApiBootSequenceContext apiBootSequenceContext;
33+
34+
@Override
35+
public void run(String... args) throws Exception {
36+
// 获取下一个String类型的ID
37+
String nextId = apiBootSequenceContext.nextStringId();
38+
// 获取下一个Long类型的ID
39+
Long nextLongId = apiBootSequenceContext.nextId();
40+
System.out.println(nextId + "," + nextLongId);
41+
}
42+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
api:
2+
boot:
3+
sequence:
4+
# 工作机器的编号,默认值为1,取值的范围:0 ~ 255
5+
worker-id: 2
6+
# 数据中心的编号,默认值为:1,取值的范围:0 ~ 3
7+
data-center-id: 0
8+
# 解决高并发下获取时间戳的性能问题
9+
clock: true

api-boot-samples/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!--跳过deploy-->
1717
<maven.deploy.skip>true</maven.deploy.skip>
1818
<!--Samples所使用的ApiBoot版本-->
19-
<api-boot.version>2.2.3.RELEASE</api-boot.version>
19+
<api-boot.version>2.2.5.RELEASE</api-boot.version>
2020
<!--Samples所使用的SpringBoot版本-->
2121
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
2222
</properties>
@@ -40,5 +40,6 @@
4040
<module>api-boot-sample-mail</module>
4141
<module>api-boot-sample-logging</module>
4242
<module>api-boot-sample-logging-admin</module>
43+
<module>api-boot-sample-sequence</module>
4344
</modules>
4445
</project>

0 commit comments

Comments
 (0)