Browse Source

集成springdoc

zhouhao 4 years ago
parent
commit
6ed2b104d1

+ 11 - 0
jetlinks-standalone/pom.xml

@@ -248,6 +248,17 @@
             <version>2.57</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.springdoc</groupId>
+            <artifactId>springdoc-openapi-webflux-ui</artifactId>
+            <version>1.4.5</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.github.xiaoymin</groupId>
+            <artifactId>knife4j-springdoc-ui</artifactId>
+            <version>2.0.5</version>
+        </dependency>
 
     </dependencies>
 

+ 2 - 49
jetlinks-standalone/src/main/java/org/jetlinks/community/standalone/configuration/ExecutorConfiguration.java

@@ -1,65 +1,18 @@
 package org.jetlinks.community.standalone.configuration;
 
-import lombok.SneakyThrows;
-import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
-import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Primary;
-import org.springframework.scheduling.annotation.AsyncConfigurer;
-import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;
 import reactor.core.scheduler.Scheduler;
 import reactor.core.scheduler.Schedulers;
 
-import java.util.concurrent.*;
-
 @Configuration
 public class ExecutorConfiguration {
 
-    @Bean
-    public AsyncConfigurer asyncConfigurer() {
-        AsyncUncaughtExceptionHandler handler = new SimpleAsyncUncaughtExceptionHandler();
-
-        return new AsyncConfigurer() {
-            @Override
-            @SneakyThrows
-            public Executor getAsyncExecutor() {
-                return threadPoolTaskExecutor().getObject();
-            }
-
-            @Override
-            public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
-                return handler;
-            }
-        };
-    }
 
     @Bean
-    public Scheduler reactorScheduler(ScheduledExecutorService executorService) {
-        return Schedulers.fromExecutorService(executorService);
+    public Scheduler reactorScheduler() {
+        return Schedulers.parallel();
     }
 
-    @Bean
-    @ConfigurationProperties(prefix = "jetlinks.executor")
-    @Primary
-    public FactoryBean<ScheduledExecutorService> threadPoolTaskExecutor() {
-        ThreadPoolExecutorFactoryBean executor = new ThreadPoolExecutorFactoryBean() {
-            @Override
-            protected ScheduledThreadPoolExecutor createExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
-
-                ScheduledThreadPoolExecutor poolExecutor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
-                poolExecutor.setMaximumPoolSize(maxPoolSize);
-                poolExecutor.setRejectedExecutionHandler(rejectedExecutionHandler);
-                poolExecutor.setKeepAliveTime(keepAliveSeconds, TimeUnit.SECONDS);
 
-                return poolExecutor;
-            }
-        };
-        executor.setThreadNamePrefix("jetlinks-thread-");
-        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
-
-        return (FactoryBean) executor;
-    }
 }

+ 3 - 2
jetlinks-standalone/src/main/java/org/jetlinks/community/standalone/configuration/JetLinksConfiguration.java

@@ -59,6 +59,7 @@ import org.springframework.context.annotation.Primary;
 import org.springframework.data.redis.core.ReactiveRedisOperations;
 import org.springframework.data.redis.core.ReactiveRedisTemplate;
 import reactor.core.publisher.EmitterProcessor;
+import reactor.core.scheduler.Scheduler;
 import reactor.core.scheduler.Schedulers;
 
 import java.util.List;
@@ -162,14 +163,14 @@ public class JetLinksConfiguration {
     public DefaultDecodedClientMessageHandler defaultDecodedClientMessageHandler(MessageHandler handler,
                                                                                  DeviceMessageConnector messageConnector,
                                                                                  DeviceSessionManager deviceSessionManager,
-                                                                                 ApplicationEventPublisher eventPublisher) {
+                                                                                 Scheduler scheduler) {
         DefaultDecodedClientMessageHandler clientMessageHandler = new DefaultDecodedClientMessageHandler(handler, deviceSessionManager,
             EmitterProcessor.create(false)
         );
         clientMessageHandler
             .subscribe()
             .parallel()
-            .runOn(Schedulers.parallel())
+            .runOn(scheduler)
             .flatMap(msg -> messageConnector.onMessage(msg).onErrorContinue((err, r) -> log.error(err.getMessage(), err)))
             .subscribe();
 

+ 35 - 1
jetlinks-standalone/src/main/resources/application.yml

@@ -139,4 +139,38 @@ micrometer:
 management:
   health:
     elasticsearch:
-      enabled: false  # 关闭elasticsearch健康检查
+      enabled: false  # 关闭elasticsearch健康检查
+springdoc:
+  swagger-ui:
+    path: /swagger-ui.html
+  #  packages-to-scan: org.jetlinks
+  group-configs:
+    - group: 设备管理相关接口
+      packages-to-scan:
+        - org.jetlinks.community.device
+      paths-to-exclude:
+        - /device-instance/**
+        - /device-product/**
+        - /protocol/**
+    - group: 规则引擎相关接口
+      packages-to-scan: org.jetlinks.community.rule.engine.web
+      paths-to-exclude: /api/**
+    - group: 通知管理相关接口
+      packages-to-scan: org.jetlinks.community.notify.manager.web
+    - group: 设备接入相关接口
+      packages-to-scan:
+        - org.jetlinks.community.network.manager.web
+        - org.jetlinks.community.device.web
+      paths-to-match:
+        - /gateway/**
+        - /network/**
+        - /protocol/**
+    - group: 系统管理相关接口
+      packages-to-scan:
+        - org.jetlinks.community.auth
+        - org.hswebframework.web.system.authorization.defaults.webflux
+        - org.hswebframework.web.file
+        - org.hswebframework.web.authorization.basic.web
+        - org.jetlinks.community.logging.controller
+  cache:
+    disabled: false