Explorar o código

添加rocketmq以及相关处理工具类

NorthLan %!s(int64=6) %!d(string=hai) anos
pai
achega
317ea82817

+ 8 - 5
build.gradle

@@ -15,8 +15,8 @@ buildscript {
         mybatis_plus_version = '2.2.0'
         mybatis_plus_boot_version = '1.0.5'
         activiti_starter_version = '6.0.0'
-//        rabbitmq_version = '5.1.2'
-        rocketmq_version = '4.2.0'
+//        rocketmq_starter_version = '1.1.0-RELEASE'
+        rocketmq_starter_version = '0.1.0'
         xxljob_version = '1.9.0'
         swagger_version = '2.7.0'
         fastjson_version = '1.2.44'
@@ -27,6 +27,7 @@ buildscript {
         dubbo_starter_version = '0.1.0'
         dubbo_version = "2.6.1"
         jsqlparser_version = '1.2'
+
     }
     repositories {
         mavenCentral()
@@ -73,7 +74,7 @@ subprojects {
         compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
         compile("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version")
 
-        kapt "org.springframework.boot:spring-boot-configuration-processor"
+        kapt("org.springframework.boot:spring-boot-configuration-processor")
         optional("org.springframework.boot:spring-boot-configuration-processor")
         // SpringBoot Starter
         compile('org.springframework.boot:spring-boot-starter')
@@ -93,7 +94,9 @@ subprojects {
 //        compile('org.springframework.session:spring-session-data-redis')
 
         // mq
-        compile("org.apache.rocketmq:rocketmq-client:$rocketmq_version")
+//        compile("org.apache.rocketmq:rocketmq-client:$rocketmq_version")
+//        compile("com.qianmi:spring-boot-starter-rocketmq:$rocketmq_starter_version")
+        compile("com.maihaoche:spring-boot-starter-rocketmq:$rocketmq_starter_version")
 
         // shiro
         compile("org.apache.shiro:shiro-spring:$shiro_version")
@@ -137,7 +140,7 @@ subprojects {
 //        compile("com.github.penggle:kaptcha:2.3.2")
         compile("com.alibaba:fastjson:$fastjson_version")
         compile("com.belerweb:pinyin4j:$pinyin4j_version")
-        compile('com.github.hotchemi:khronos:0.9.0')
+//        compile('com.github.hotchemi:khronos:0.9.0')
         compile('com.github.shihyuho:jackson-dynamic-filter:1.0')
 
         // rpc

+ 17 - 0
zen-api/src/main/kotlin/com/gxzc/zen/msg/mq/MQConfiguration.kt

@@ -0,0 +1,17 @@
+package com.gxzc.zen.msg.mq
+
+import com.maihaoche.starter.mq.annotation.EnableMQConfiguration
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
+import org.springframework.context.annotation.Configuration
+
+/**
+ *
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+@Configuration
+@ConditionalOnProperty(prefix = "spring.rocketmq", name = ["enabled"], havingValue = "true")
+@EnableMQConfiguration
+class MQConfiguration {
+}

+ 19 - 0
zen-api/src/main/kotlin/com/gxzc/zen/msg/mq/MQProducerUtil.kt

@@ -0,0 +1,19 @@
+package com.gxzc.zen.msg.mq
+
+import com.gxzc.zen.common.util.SpringContextHolder
+
+/**
+ * MQ生产者工具类
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+object MQProducerUtil {
+    var producer: ZenMQProducer? = null
+        get() {
+            if (field == null) {
+                field = SpringContextHolder.getBean(ZenMQProducer::class.java)
+            }
+            return field
+        }
+}

+ 16 - 0
zen-api/src/main/kotlin/com/gxzc/zen/msg/mq/ZenMQProducer.kt

@@ -0,0 +1,16 @@
+package com.gxzc.zen.msg.mq
+
+import com.maihaoche.starter.mq.annotation.EnableMQConfiguration
+import com.maihaoche.starter.mq.annotation.MQProducer
+import com.maihaoche.starter.mq.base.AbstractMQProducer
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
+
+/**
+ * MQ 消息生产者
+ * @author NorthLan
+ * @date 2018/8/21
+ * @url https://noahlan.com
+ */
+@MQProducer
+@ConditionalOnBean(annotation = [EnableMQConfiguration::class])
+class ZenMQProducer : AbstractMQProducer()

+ 31 - 0
zen-api/src/main/kotlin/com/gxzc/zen/msg/mq/constants/MQConstants.kt

@@ -0,0 +1,31 @@
+package com.gxzc.zen.msg.mq.constants
+
+/**
+ * MQ 各种常量
+ * @author NorthLan
+ * @date 2018/8/23
+ * @url https://noahlan.com
+ */
+object MQConstants {
+    /*-------------------------------------------
+    |                Topic 常 量                |
+    ============================================*/
+    const val TOPIC_LOGS = "topic_logs" // logs系统的topic
+
+    /*-------------------------------------------
+    |                TAGS 常 量                 |
+    ============================================*/
+    const val TAGS_LOGS_AUTH = "auth" // 登录
+    const val TAGS_LOGS_REQUEST = "request" // 请求
+    const val TAGS_LOGS_DB = "db" // 数据库操作
+    const val TAGS_LOGS_BIZ = "biz" // 业务
+
+
+    /*-------------------------------------------
+    |            Consumer Group 常 量            |
+    ============================================*/
+    const val CONSUMER_GROUP_LOGS_AUTH = "group_logs_auth" // 登录TAG-消费组
+    const val CONSUMER_GROUP_LOGS_REQUEST = "group_logs_request" // 请求TAG-消费组
+    const val CONSUMER_GROUP_LOGS_DB = "group_logs_db" // 数据库操作TAG-消费组
+    const val CONSUMER_GROUP_LOGS_BIZ = "group_logs_biz" // 业务TAG-消费组
+}

+ 7 - 7
zen-api/src/main/kotlin/com/gxzc/zen/orm/config/MybatisPlusConfig.kt

@@ -31,11 +31,11 @@ class MybatisPlusConfig {
         return PaginationInterceptor()
     }
 
-    /**
-     * 数据权限插件
-     */
-    @Bean
-    fun zenDataAuthorityInterceptor(): ZenDataAuthorityInterceptor {
-        return ZenDataAuthorityInterceptor()
-    }
+//    /**
+//     * 数据权限插件
+//     */
+//    @Bean
+//    fun zenDataAuthorityInterceptor(): ZenDataAuthorityInterceptor {
+//        return ZenDataAuthorityInterceptor()
+//    }
 }

+ 1 - 3
zen-api/src/main/kotlin/com/gxzc/zen/umps/config/ZenWebSessionManager.kt

@@ -186,9 +186,7 @@ class ZenWebSessionManager : DefaultSessionManager {
         }
 
         ////////////////////////Add by noahlan//////////////////////////////////
-        if (request != null) {
-            request.setAttribute(sessionId.toString(), s)
-        }
+        request?.setAttribute(sessionId.toString(), s)
         ///////////////////////////////////////////////////////////////////////
         return s
     }

+ 6 - 6
zen-core/src/main/kotlin/com/gxzc/zen/common/contants/ZenConstants.kt

@@ -23,29 +23,29 @@ object ZenConstants {
     /*-------------------------------------------
     |              系 统 参 数 KEY               |
     ============================================*/
-    final val PARAMKEY_SUPER_ACCOUNT = "superAccount"
+    const val PARAMKEY_SUPER_ACCOUNT = "superAccount"
     /**
      * 系统数据权限开关
      */
-    final val PARAMKEY_SYS_DA_ENABLED = "sysDAEnabled"
+    const val PARAMKEY_SYS_DA_ENABLED = "sysDAEnabled"
 
     /**
      * 用户数据权限开关
      */
-    final val PARAMKEY_USER_DA_ENABLED = "userDAEnabled"
+    const val PARAMKEY_USER_DA_ENABLED = "userDAEnabled"
 
     /**
      * 角色数据权限开关
      */
-    final val PARAMKEY_ROLE_DA_ENABLED = "roleDAEnabled"
+    const val PARAMKEY_ROLE_DA_ENABLED = "roleDAEnabled"
 
     /**
      * 部门数据权限开关
      */
-    final val PARAMKEY_DEPT_DA_ENABLED = "deptDAEnabled"
+    const val PARAMKEY_DEPT_DA_ENABLED = "deptDAEnabled"
 
     /**
      * 岗位数据权限开关
      */
-    final val PARAMKEY_POST_DA_ENABLED = "postDAEnabled"
+    const val PARAMKEY_POST_DA_ENABLED = "postDAEnabled"
 }

+ 1 - 2
zen-core/src/main/kotlin/com/gxzc/zen/common/dto/ResponseDto.kt

@@ -2,7 +2,6 @@ package com.gxzc.zen.common.dto
 
 import com.fasterxml.jackson.annotation.JsonFormat
 import com.fasterxml.jackson.annotation.JsonInclude
-import khronos.Dates
 import java.io.Serializable
 import java.util.*
 
@@ -23,7 +22,7 @@ open class ResponseDto : Serializable {
     var code: Int? = 200
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    var time: Date = Dates.today
+    var time: Date = Date()
 
     fun data(data: Any?): ResponseDto {
         this.data = data

+ 1 - 0
zen-web/src/main/kotlin/com/gxzc/zen/MainApplication.kt

@@ -13,6 +13,7 @@ import org.springframework.context.annotation.ImportResource
 //@ImportResource(locations = ["classpath:application-shiro.xml"])
 @ImportResource(locations = ["classpath:dubbo/*.xml"])
 //@EnableRedisHttpSession
+//@EnableMQConfiguration
 class MainApplication : SpringBootServletInitializer() {
     override fun configure(builder: SpringApplicationBuilder?): SpringApplicationBuilder? {
         return builder?.sources(MainApplication::class.java)

+ 50 - 5
zen-web/src/main/kotlin/com/gxzc/zen/web/sys/controller/TestController.kt

@@ -1,8 +1,10 @@
 package com.gxzc.zen.web.sys.controller
 
 import com.gxzc.zen.api.sys.service.ISysUploadInfoService
-import com.gxzc.zen.api.util.SysDictUtil
 import com.gxzc.zen.common.base.BaseController
+import com.gxzc.zen.msg.mq.MQProducerUtil
+import com.maihaoche.starter.mq.base.MessageBuilder
+import org.apache.shiro.SecurityUtils
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.http.ResponseEntity
 import org.springframework.web.bind.annotation.GetMapping
@@ -19,17 +21,60 @@ import org.springframework.web.bind.annotation.RestController
 @RestController
 @RequestMapping("test")
 class TestController : BaseController() {
+
+    @Autowired
+    private lateinit var sysUploadInfoService: ISysUploadInfoService
+
+    //    @Autowired
+    //    private lateinit var mqProducer: ZenMQProducer
+
     @GetMapping("a")
     fun get(): ResponseEntity<*> {
-        return ResponseEntity.ok(SysDictUtil.getAll())
+        return ResponseEntity.ok(2)
     }
 
 
-    @Autowired
-    private lateinit var sysUploadInfoService: ISysUploadInfoService
-
     @GetMapping("b")
     fun getb(): ResponseEntity<*> {
         return ResponseEntity.ok(sysUploadInfoService.selectList(null))
     }
+
+    @GetMapping("thread")
+    fun niubi(): ResponseEntity<*> {
+        val subject = SecurityUtils.getSubject()
+        println(subject.principal)
+        val runnable = Thread(Runnable {
+            kotlin.run {
+                Thread.sleep(2000)
+                val sub = SecurityUtils.getSubject()
+                println(sub.principal)
+            }
+        })
+        //        subject.execute {
+        runnable.start()
+        //        }
+        return ResponseEntity.ok("2333")
+    }
+
+    @GetMapping("mq")
+    fun mq(): ResponseEntity<*> {
+        MQProducerUtil.producer?.syncSend(MessageBuilder.of("2333").build())
+        return ResponseEntity.ok(1234)
+    }
+
+    @GetMapping("file")
+    fun md5(): ResponseEntity<*> {
+        //        println(FileUtil.md5HeadTail("/newfile/4/WS·1983/综合/永久/4·WS-1983-综合-0001.pdf", null))
+        //        println(FileUtil.md5HeadTail("D:/data/4·WS-1983-综合-0001.pdf", null))
+
+        //
+        //        FileUtils.copyFile(File("D:/data/123.pdf"),File("D:/321.pdf"))
+        //
+        //        println(FileUtil.md5HeadTail("D:/data/123.pdf", 10485760))
+        //        println(FileUtil.md5HeadTail("D:/321.pdf", 10485760))
+
+        //        println(FileUtil.md5HeadTail("D:/123.pdf", null))
+        //        println(FileUtil.md5HeadTail("D:/data/", null))
+        return ResponseEntity.ok(2333)
+    }
 }

+ 16 - 30
zen-web/src/main/resources/application-msg.yml

@@ -1,40 +1,26 @@
 spring:
   profiles: dev
-  rabbitmq:
-    enable: false
-    host: localhost
-    port: 5672
-    username: admin
-    password: admin
-    publisher-confirms: true
-    publisher-returns: true
-    template:
-      mandatory: true
-    listener:
-      simple:
-        concurrency: 2 # 最小消息监听线程数
-        max-concurrency: 2 # 最大消息监听线程数
-    virtual-host: /
+  rocketmq:
+    enabled: true
+    name-server-address: 192.168.1.10:9876
+    producer-group: zen-archives-group
+    send-msg-timeout: 5000
+    trace-enabled: false
+    vip-channel-enabled: true
+
 ws:
   enabled: false
 
 ---
 spring:
   profiles: prod
-  rabbitmq:
-    enable: false
-    host: localhost
-    port: 5672
-    username: admin
-    password: admin
-    publisher-confirms: true
-    publisher-returns: true
-    template:
-      mandatory: true
-    listener:
-      simple:
-        concurrency: 2 # 最小消息监听线程数
-        max-concurrency: 2 # 最大消息监听线程数
-    virtual-host: /
+  rocketmq:
+    enabled: true
+    name-server-address: 192.168.1.10:9876
+    producer-group: zen-archives-group
+    send-msg-timeout: 5000
+    trace-enabled: false
+    vip-channel-enabled: true
+
 ws:
   enabled: false

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

@@ -31,6 +31,7 @@ logging:
       zen.umps.config: warn
     com.xxl.job.core: warn
     com.atomikos: warn
+    com.maihaoche: debug
   path: ./logs/
   file: zen.log