Skip to content

Commit

Permalink
Update codes
Browse files Browse the repository at this point in the history
  • Loading branch information
onemsg committed Oct 26, 2023
1 parent 46e75e5 commit cca13c7
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.autobuild.enabled": false,
"java.autobuild.enabled": true,
"java.eclipse.downloadSources": true,
"java.maven.downloadSources": true,
"java.jdt.ls.vmargs": "-XX:+UseZGC -Xmx16G -Xms200m -javaagent:\"c:\\Users\\kvims\\.vscode\\extensions\\gabrielbb.vscode-lombok-1.0.1\\server\\lombok.jar\"",
"java.compile.nullAnalysis.mode": "automatic",
"java.format.settings.url": ".vscode/java-formatter.xml",
}
46 changes: 39 additions & 7 deletions authorization-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.4</version>
<version>3.1.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.onemsg</groupId>
Expand All @@ -15,14 +15,46 @@

<properties>
<java.version>17</java.version>

<micrometer.version>1.8.5</micrometer.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-bom</artifactId>
<version>${micrometer.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-otel</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-observation</artifactId>
</dependency>

<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ server.port=9900
server.http2.enabled=true
server.undertow.threads.io=3
server.undertow.threads.worker=24
spring.mvc.problemdetails.enabled=true
server.error.include-message=ALWAYS
server.error.include-stacktrace=NEVER

Expand Down
35 changes: 16 additions & 19 deletions protobuf-manager-spring/pom.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 https://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>3.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
<version>3.1.2</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<groupId>com.onemsg</groupId>
<artifactId>protobuf-manager-spring</artifactId>
<version>1.0.1</version>

<name>protobuf-manager-spring</name>
<description>protobuf manager </description>

<properties>
<java.version>17</java.version>
</properties>
<dependencies>

<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency> -->


<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -47,8 +45,8 @@
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

<dependency>
Expand Down Expand Up @@ -95,8 +93,7 @@
<configuration>
<excludes>
<exclude>
<groupId>
org.projectlombok</groupId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
import java.util.stream.Collectors;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.event.EventListener;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.lang.Nullable;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.onemsg.protobuf.manager.application.event.RefreshGroupStoreEvent;
import com.onemsg.protobuf.manager.application.model.Group;
import com.onemsg.protobuf.manager.exception.DataModelResponseException;
import com.onemsg.protobuf.manager.exception.NotExistedException;
Expand All @@ -28,13 +32,15 @@
@Slf4j
@AllArgsConstructor
@Service
public class GroupService implements InitializingBean {
public class GroupService implements InitializingBean, ApplicationEventPublisherAware {

private final GroupRepository groupRepository;
private final ThreadPoolTaskExecutor executor;

private final AtomicReference<Map<Integer, Group.Entity>> groupStore = new AtomicReference<>(Collections.emptyMap());
private final AtomicReference<Map<Integer, Group.Entity>> groupStore = new AtomicReference<>(
Collections.emptyMap());

@EventListener(RefreshGroupStoreEvent.class)
@Scheduled(fixedDelay = 30, timeUnit = TimeUnit.SECONDS)
public void refreshStore() {
List<Group.Entity> groups = groupRepository.findAll();
Expand All @@ -43,19 +49,17 @@ public void refreshStore() {
groupStore.set(groupMap);
}

private void asyncRefreshStore() {
executor.submit(this::refreshStore);
}
// private void asyncRefreshStore() {
// executor.submit(this::refreshStore);
// }

public Collection<Group.Entity> getAll() {
return groupStore.get().values();
}

public List<Group.NameVo> getAllNames() {
return groupStore.get().values().stream()
.map(Group.NameVo::create)
.sorted(Comparator.comparing(Group.NameVo::name))
.toList();
return groupStore.get().values().stream().map(Group.NameVo::create)
.sorted(Comparator.comparing(Group.NameVo::name)).toList();
}

@Nullable
Expand All @@ -67,7 +71,7 @@ public Group.Entity getById(int id) {
public int create(String name, String intro, String creator) throws DataModelResponseException {
try {
int id = groupRepository.save(name, intro, creator);
asyncRefreshStore();
publishRefreshEvent();
return id;
} catch (DuplicateKeyException e) {
throw new DataModelResponseException(400, 400, String.format("Group name [%s] 已存在", name));
Expand All @@ -78,7 +82,7 @@ public int create(String name, String intro, String creator) throws DataModelRes
public void updateIntro(int id, String intro) throws NotExistedException {
existById(id);
groupRepository.updateIntroById(id, intro);
asyncRefreshStore();
publishRefreshEvent();
}

public void existById(int id) throws NotExistedException {
Expand All @@ -93,4 +97,15 @@ public void afterPropertiesSet() throws Exception {
refreshStore();
log.info("Load group store ok");
}

private ApplicationEventPublisher publisher;

@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
publisher = applicationEventPublisher;
}

public void publishRefreshEvent() {
publisher.publishEvent(new RefreshGroupStoreEvent(this));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onemsg.protobuf.manager.web;

import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import java.util.Objects;

import org.springframework.http.ResponseEntity;
import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ server.port=5000
server.http2.enabled=true
server.undertow.threads.io=3
server.undertow.threads.worker=24
spring.mvc.problemdetails.enabled=true
server.error.include-message=ALWAYS
server.error.include-stacktrace=NEVER
server.servlet.jsp.registered=false
spring.mvc.problemdetails.enabled=true

spring.mvc.log-resolved-exception=false

spring.task.execution.pool.core-size=3

spring.datasource.url=jdbc:mysql://localhost:3306/protobuf_manager
spring.datasource.username=onemsg
spring.datasource.password=123456
spring.datasource.password=123456

spring.devtools.restart.enabled=true
spring.devtools.livereload.enabled=true
2 changes: 1 addition & 1 deletion protobuf-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>

<vertx.version>4.3.1</vertx.version>
<vertx.version>4.4.4</vertx.version>
<junit-jupiter.version>5.7.0</junit-jupiter.version>

<launcher.class>com.onemsg.protobuf.manager.Launcher</launcher.class>
Expand Down
7 changes: 7 additions & 0 deletions test-api.rest
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ GET {{devhost}}/api/400



$ jlink `
--add-modules java.base `
--strip-debug `
--no-man-pages `
--no-header-files `
--compress=2 `
--output /javaruntime
26 changes: 25 additions & 1 deletion test-spring-api.rest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@devhost=http://localhost:5000
@cookie=auth_name=Spring;auth_token=3oo6h3a2n1h6q733ca
@cookie=auth_name=Spring;auth_token=6s2y463m5t30667605s

## About user

Expand Down Expand Up @@ -137,3 +137,27 @@ Cookie: {{cookie}}
###
GET {{devhost}}/api/protobuf/1/code
Cookie: {{cookie}}

###
GET {{devhost}}/sleep?time=1000
Cookie: {{cookie}}

###
GET {{devhost}}/test-null

###
GET {{devhost}}/test-null-html
# Accept: text/html

###
GET {{devhost}}/error

###
GET {{devhost}}/test-exception

###
GET {{devhost}}/test-exception
Accept: text/html

###
GET {{devhost}}/404

0 comments on commit cca13c7

Please sign in to comment.