Browse Source

移除activiti模块(由需要的业务系统自行搭建),添加job模块(job执行器)

NorthLan 7 years ago
parent
commit
563d08706c

+ 1 - 1
settings.gradle

@@ -5,5 +5,5 @@ include 'zen-orm'
 include 'zen-api'
 include 'zen-web'
 include 'zen-mq'
-include 'zen-activiti'
+include 'zen-job'
 

+ 0 - 2
zen-activiti/build.gradle

@@ -1,2 +0,0 @@
-dependencies {
-}

+ 0 - 76
zen-activiti/src/main/resources/processes/test.bpmn

@@ -1,76 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1517475747589" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
-  <process id="myProcess_1" isClosed="false" isExecutable="true" processType="None">
-    <startEvent id="_2" name="StartEvent"/>
-    <userTask activiti:exclusive="true" id="_3" name="UserTask"/>
-    <sequenceFlow id="_4" sourceRef="_2" targetRef="_3"/>
-    <endEvent id="_5" name="EndEvent"/>
-    <userTask activiti:exclusive="true" id="_7" name="UserTask"/>
-    <sequenceFlow id="_8" sourceRef="_3" targetRef="_7"/>
-    <userTask activiti:exclusive="true" id="_9" name="UserTask"/>
-    <sequenceFlow id="_10" sourceRef="_7" targetRef="_9"/>
-    <sequenceFlow id="_11" sourceRef="_9" targetRef="_5"/>
-  </process>
-  <bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
-    <bpmndi:BPMNPlane bpmnElement="myProcess_1">
-      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
-        <omgdc:Bounds height="32.0" width="32.0" x="75.0" y="70.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
-        <omgdc:Bounds height="55.0" width="155.0" x="290.0" y="45.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="55.0" width="155.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
-        <omgdc:Bounds height="32.0" width="32.0" x="615.0" y="115.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
-        <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="205.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNShape bpmnElement="_9" id="Shape-_9">
-        <omgdc:Bounds height="55.0" width="85.0" x="490.0" y="90.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNShape>
-      <bpmndi:BPMNEdge bpmnElement="_4" id="BPMNEdge__4" sourceElement="_2" targetElement="_3">
-        <omgdi:waypoint x="107.0" y="86.0"/>
-        <omgdi:waypoint x="290.0" y="72.5"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_3" targetElement="_7">
-        <omgdi:waypoint x="357.5" y="100.0"/>
-        <omgdi:waypoint x="357.5" y="205.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_9" targetElement="_5">
-        <omgdi:waypoint x="575.0" y="117.5"/>
-        <omgdi:waypoint x="615.0" y="131.0"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_7" targetElement="_9">
-        <omgdi:waypoint x="400.0" y="232.5"/>
-        <omgdi:waypoint x="490.0" y="117.5"/>
-        <bpmndi:BPMNLabel>
-          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
-        </bpmndi:BPMNLabel>
-      </bpmndi:BPMNEdge>
-    </bpmndi:BPMNPlane>
-  </bpmndi:BPMNDiagram>
-</definitions>

+ 1 - 0
zen-core/src/main/kotlin/com/gxzc/zen/common/config/CacheConfig.kt

@@ -1,6 +1,7 @@
 package com.gxzc.zen.common.config
 
 import com.github.benmanes.caffeine.cache.Caffeine
+import com.gxzc.zen.common.persistance.CacheSpec
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 import org.springframework.boot.context.properties.ConfigurationProperties
 import org.springframework.cache.CacheManager

+ 1 - 1
zen-core/src/main/kotlin/com/gxzc/zen/common/config/CacheSpec.kt → zen-core/src/main/kotlin/com/gxzc/zen/common/persistance/CacheSpec.kt

@@ -1,4 +1,4 @@
-package com.gxzc.zen.common.config
+package com.gxzc.zen.common.persistance
 
 /**
  * 缓存配置数据类

+ 57 - 0
zen-job/src/main/kotlin/com/gxzc/zen/job/config/XxlJobConfig.kt

@@ -0,0 +1,57 @@
+package com.gxzc.zen.job.config
+
+import com.xxl.job.core.executor.XxlJobExecutor
+import org.mybatis.spring.annotation.MapperScan
+import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.annotation.Value
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.context.annotation.Bean
+import org.springframework.context.annotation.Configuration
+
+/**
+ *
+ * @author NorthLan at 2018/2/8
+ */
+@Configuration
+@ConditionalOnProperty(prefix = "xxl.job", name = ["enable"], havingValue = "true", matchIfMissing = true)
+@MapperScan(basePackages = ["com.gxzc.zen.job.jobhandler"])
+class XxlJobConfig {
+    companion object {
+        private val logger = LoggerFactory.getLogger(XxlJobConfig::class.java)
+    }
+
+    @Value("\${xxl.job.admin.address}")
+    private val adminAddress: String? = null
+
+    @Value("\${xxl.job.executor.appname}")
+    private val appName: String? = null
+
+    @Value("\${xxl.job.executor.ip}")
+    private val ip: String? = null
+
+    @Value("\${xxl.job.executor.port}")
+    private val port: Int = 0
+
+    @Value("\${xxl.job.accessToken}")
+    private val accessToken: String? = null
+
+    @Value("\${xxl.job.executor.logpath}")
+    private val logPath: String? = null
+
+    @Value("\${xxl.job.executor.logretentiondays}")
+    private val logRetentionDays: Int = 0
+
+    @Bean
+    fun xxlJobExecutor(): XxlJobExecutor {
+        logger.info(">>>>>>>>>>>> xxl-job executor config init...")
+        return XxlJobExecutor().also {
+            it.setAdminAddresses(adminAddress)
+            it.setAppName(appName)
+            it.setIp(ip)
+            it.setPort(port)
+            it.setAccessToken(accessToken)
+            it.setLogPath(logPath)
+            it.setLogRetentionDays(logRetentionDays)
+        }
+    }
+}

+ 33 - 0
zen-job/src/main/kotlin/com/gxzc/zen/job/jobhandler/DemoJobHandler.kt

@@ -0,0 +1,33 @@
+package com.gxzc.zen.job.jobhandler
+
+import com.xxl.job.core.biz.model.ReturnT
+import com.xxl.job.core.handler.IJobHandler
+import com.xxl.job.core.handler.annotation.JobHandler
+import com.xxl.job.core.log.XxlJobLogger
+import org.springframework.stereotype.Component
+import java.util.concurrent.TimeUnit
+
+/**
+ * 任务Handler示例(Bean模式)
+ *
+ * 开发步骤:
+ * 1、继承"IJobHandler":“com.xxl.job.core.handler.IJobHandler”;
+ * 2、注册到Spring容器:添加“@Component”注解,被Spring容器扫描为Bean实例;
+ * 3、注册到执行器工厂:添加“@JobHandler(value="自定义jobhandler名称")”注解,注解value值对应的是调度中心新建任务的JobHandler属性的值。
+ * 4、执行日志:需要通过 "XxlJobLogger.log" 打印执行日志;
+ *
+ * @author NorthLan at 2018/2/8
+ */
+@JobHandler("demoJobHandler")
+@Component
+class DemoJobHandler : IJobHandler() {
+    override fun execute(param: String): ReturnT<String> {
+        XxlJobLogger.log("xxl-job, Hello world!")
+        for (i in 1..5) {
+            XxlJobLogger.log("beat at: $i")
+            TimeUnit.SECONDS.sleep(2)
+        }
+        return SUCCESS
+    }
+
+}

+ 12 - 0
zen-job/src/main/resources/application-job.yml

@@ -0,0 +1,12 @@
+xxl:
+  job:
+    enable: true
+    admin:
+      address: http://127.0.0.1:8080/xxl-job-admin
+    executor:
+      appname: xxl-job-executor-sample
+      ip:
+      port: 9999
+      logpath: /data/applogs/xxl-job/jobhandler
+      logretentiondays: -1
+    accessToken: ""

+ 3 - 3
zen-orm/src/main/resources/application-orm-local.yml

@@ -22,7 +22,7 @@ spring:
       validation-query: SELECT 1
       async-init: false
       name: system
-      filters: logback,log4j,wall,mergeStat
+      filters: log4j,wall,mergeStat
       keep-alive: false
       initial-size: 5
       min-idle: 5
@@ -43,7 +43,7 @@ datasource:
     test-while-idle: true
     validation-query: SELECT 1
     async-init: false
-    filters: logback,log4j,wall,mergeStat
+    filters: log4j,wall,mergeStat
     keep-alive: false
     initial-size: 5
     min-idle: 5
@@ -61,7 +61,7 @@ datasource:
     test-while-idle: true
     validation-query: SELECT 1
     async-init: false
-    filters: logback,log4j,wall,mergeStat
+    filters: log4j,wall,mergeStat
     keep-alive: false
     initial-size: 5
     min-idle: 5

+ 3 - 3
zen-orm/src/main/resources/application-orm.yml

@@ -22,7 +22,7 @@ spring:
       validation-query: SELECT 1
       async-init: false
       name: system
-      filters: logback,log4j,wall,mergeStat
+      filters: log4j,wall,mergeStat
       keep-alive: false
       initial-size: 5
       min-idle: 5
@@ -43,7 +43,7 @@ datasource:
     test-while-idle: true
     validation-query: SELECT 1
     async-init: false
-    filters: logback,log4j,wall,mergeStat
+    filters: log4j,wall,mergeStat
     keep-alive: false
     initial-size: 5
     min-idle: 5
@@ -61,7 +61,7 @@ datasource:
     test-while-idle: true
     validation-query: SELECT 1
     async-init: false
-    filters: logback,log4j,wall,mergeStat
+    filters: log4j,wall,mergeStat
     keep-alive: false
     initial-size: 5
     min-idle: 5

+ 1 - 5
zen-umps/src/main/kotlin/com/gxzc/zen/umps/KissoAuthorization.kt

@@ -7,15 +7,11 @@ import com.gxzc.zen.common.util.PlatformUtil
 import com.gxzc.zen.common.util.SpringContextHolder
 import com.gxzc.zen.umps.util.PermissionUtil
 import org.apache.commons.lang3.StringUtils
-import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.cache.CacheManager
-import org.springframework.stereotype.Component
 
-@Component
 class KissoAuthorization : SSOAuthorization {
 
-    @Autowired
-    private lateinit var cacheManager: CacheManager
+    private val cacheManager = SpringContextHolder.getBean(CacheManager::class.java)
 
     private val permissionService = SpringContextHolder.getBean(ISysPermissionService::class.java)
 

+ 1 - 0
zen-web/build.gradle

@@ -6,4 +6,5 @@ dependencies {
     compile project(":zen-api")
     compile project(":zen-umps")
     compile project(":zen-mq")
+    compile project(":zen-job")
 }

+ 1 - 1
zen-web/src/main/resources/application.yml

@@ -6,7 +6,7 @@ server:
 spring:
   profiles:
     active: dev
-    include: orm,mq,cache,umps,platform
+    include: orm-local,mq,cache,umps,platform,job
 #  redis:
 #    host: localhost
 #    port: 6379