Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/spring boot starter dailysegment #173

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
20336a3
init support springboot
Oct 9, 2019
48be19d
init support springboot
Oct 9, 2019
6dd639f
init support springboot
Oct 9, 2019
d69356e
init support springboot
Oct 9, 2019
7daaf9c
adjust code style
thelight1 Oct 12, 2019
dd5f2e0
add shell
Yaccc Feb 21, 2020
6c88fe3
Update README_CN.md
Yaccc Feb 21, 2020
a873b98
change readme
Feb 21, 2020
9df57e9
change readme
Mar 15, 2020
a255cc3
change readme
Mar 15, 2020
064a9d9
change readme
Mar 15, 2020
ea7734e
meger start branch
Mar 15, 2020
ea5685a
init support springboot
Oct 9, 2019
48de334
init support springboot
Oct 9, 2019
1519c15
move class to support starter
Mar 15, 2020
d70e539
move class to support starter
Mar 15, 2020
a483e90
move class to support starter
Mar 15, 2020
1539459
move class to support starter
Mar 15, 2020
cb16a72
move class to support starter
Mar 15, 2020
475763c
move class to support starter
Mar 15, 2020
1e73d46
move class to support starter
Mar 15, 2020
ba8b196
move class to support starter
Mar 21, 2020
6573b7a
readme文档
Mar 21, 2020
a131db7
readme文档
Mar 21, 2020
269f84d
readme文档
Mar 21, 2020
5b095f7
readme文档
Mar 21, 2020
8be4338
Merge branch 'master' into feature/spring-boot-starter
Mar 21, 2020
6a0c3f7
Update README_CN.md
Yaccc Apr 12, 2020
bb15c2a
每日的进行订正数据
nogeek-cn Jul 1, 2021
c33a100
fixed bugs and add example
nogeek-cn Jul 2, 2021
7d89cd7
add md sql
nogeek-cn Jul 2, 2021
6d32274
fix sql
nogeek-cn Jul 5, 2021
8e47b5f
5 分钟一次修复
nogeek-cn Jul 5, 2021
42d948b
fix
nogeek-cn Jul 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,56 @@ Leaf 最早期需求是各个业务线的订单ID生成需求。在美团早期

## Quick Start

### 使用leaf-starter注解来启动leaf

```shell script
git clone git@github.com:Meituan-Dianping/Leaf.git
git checkout feature/spring-boot-starter
cd leaf
mvn clean install -Dmaven.test.skip=true
```
#### 引入依赖
```xml
<dependency>
<artifactId>leaf-boot-starter</artifactId>
<groupId>com.sankuai.inf.leaf</groupId>
<version>1.0.1-RELEASE</version>
</dependency>
```
#### 配置leaf.properties到你的classpath下面
```properties
leaf.name=com.sankuai.leaf.opensource.test
leaf.segment.enable=false
#leaf.segment.url=
#leaf.segment.username=
#leaf.segment.password=

leaf.snowflake.enable=false
#leaf.snowflake.address=
#leaf.snowflake.port=
```
#### 利用注解启动leaf,并使用api
```java
//EnableLeafServer 开启leafserver
@SpringBootApplication
@EnableLeafServer
public class LeafdemoApplication {

public static void main(String[] args) {
SpringApplication.run(LeafdemoApplication.class, args);
}
}
//直接使用 spring注入
public class T {
@Autowired
private SegmentService segmentService;
@Autowired
private SnowflakeService snowflakeService;
}
```

TIPS:后续会将jar包上传的maven仓库

### 使用注解启动leaf
https://github.com/Meituan-Dianping/Leaf/blob/feature/spring-boot-starter/README_CN.md

Expand Down
48 changes: 48 additions & 0 deletions daily_leaf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
```sql

CREATE TABLE `leaf_alloc`
(
`biz_tag` varchar(128) NOT NULL DEFAULT '',
`max_id` bigint(20) NOT NULL DEFAULT '1',
`step` int(11) NOT NULL,
`description` varchar(256) DEFAULT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB;

```


```sql

CREATE TABLE `daily_leaf_alloc`
(
`biz_tag` varchar(128) NOT NULL DEFAULT '',
`max_id` bigint(20) NOT NULL DEFAULT '1',
`step` int(11) NOT NULL,
`description` varchar(256) DEFAULT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`biz_tag`)
) ENGINE=InnoDB;

```

```sql


INSERT INTO daily_leaf_alloc (
biz_tag,
max_id,
step,
description
)
VALUES
(
'TEST',
1,
2000,
'Test leaf Segment Mode Get Id'
)


```
30 changes: 24 additions & 6 deletions leaf-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
<parent>
<groupId>com.sankuai.inf.leaf</groupId>
<artifactId>leaf-parent</artifactId>
<version>1.0.1</version>
<version>1.0.1-RELEASE</version>
</parent>
<groupId>com.sankuai.inf.leaf</groupId>
<artifactId>leaf-core</artifactId>
<packaging>jar</packaging>
<version>1.0.1</version>
<version>1.0.1-RELEASE</version>
<name>leaf-core</name>
<properties>
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
<!-- <mysql-connector-java.version>5.1.38</mysql-connector-java.version>-->
<commons-io.version>2.4</commons-io.version>
<log4j.version>2.7</log4j.version>
<mybatis-spring.version>1.2.5</mybatis-spring.version>
Expand Down Expand Up @@ -73,7 +73,6 @@
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
Expand Down Expand Up @@ -104,12 +103,31 @@
<artifactId>mybatis-spring</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sankuai.inf.leaf.server;
package com.sankuai.inf.leaf;

public class Constants {
public static final String LEAF_SEGMENT_ENABLE = "leaf.segment.enable";
Expand Down
32 changes: 32 additions & 0 deletions leaf-core/src/main/java/com/sankuai/inf/leaf/common/DateUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sankuai.inf.leaf.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/***
*
*
* @author <a href="mailto:1934849492@qq.com">Darian</a>
* @date 2021/7/1 21:56
*/
public class DateUtils {

public static String formatyyyyMMdd(Date date) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
return simpleDateFormat.format(date);
}

/**
* 在输入日期上增加(+)或减去(-)天数
*
* @param date 输入日期
* @param days 要增加或减少的天数
*/
public static Date addDay(Date date, int days) {
Calendar cd = Calendar.getInstance();
cd.setTime(date);
cd.add(Calendar.DAY_OF_MONTH, days);
return cd.getTime();
}
}
52 changes: 52 additions & 0 deletions leaf-core/src/main/java/com/sankuai/inf/leaf/common/ListUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.sankuai.inf.leaf.common;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/***
*
*
* @author <a href="mailto:1934849492@qq.com">Darian</a>
* @date 2021/7/1 22:27
*/
public class ListUtils {

/**
* 将数据按照固定大小进行切割
*
* @param stringList
* @param maxSend
* @return
*/
public static List<List<String>> splitList(List<String> stringList, Integer maxSend) {
int limit = countStep(stringList.size(), maxSend);
return Stream.iterate(0, n -> n + 1)
.limit(limit)
.parallel()
.map(a -> stringList.stream()
.skip(a * maxSend)
.limit(maxSend)
.parallel()
.collect(Collectors.toList()))
.collect(Collectors.toList());
}

/**
* 计算切分次数
*/
private static Integer countStep(Integer size, Integer maxSend) {
return (size + maxSend - 1) / maxSend;
}

public static void main(String[] args) {
List<String> strings = Arrays.asList("a", "c", "b", "a");
System.out.println(splitList(strings, 1));
System.out.println();
System.out.println(splitList(strings, 2));
System.out.println();
System.out.println(splitList(strings, 3));
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
package com.sankuai.inf.leaf.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;

public class PropertyFactory {
private static final Logger logger = LoggerFactory.getLogger(PropertyFactory.class);
private static final Properties prop = new Properties();
static {
try {
prop.load(PropertyFactory.class.getClassLoader().getResourceAsStream("leaf.properties"));
} catch (IOException e) {
logger.warn("Load Properties Ex", e);
}
}
public static Properties getProperties() {
return prop;
public static String leafname;
public static void setLeafName(String leafName){
PropertyFactory.leafname=leafName;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sankuai.inf.leaf.server.exception;
package com.sankuai.inf.leaf.exception;

public class InitException extends Exception{
public InitException(String msg) {
Expand Down
Loading