ソースを参照

callback服务使用xxl-mq

xuzuoyun 5 年 前
コミット
020a624d23

+ 99 - 49
module-callback/pom.xml

@@ -2,10 +2,14 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
-  <groupId>org.jeecgframework.boot</groupId>
+  <groupId>cn.com.ctop</groupId>
   <artifactId>module-callback</artifactId>
   <version>2.0.2</version>
-
+  <parent>
+    <groupId>org.jeecgframework.boot</groupId>
+    <artifactId>jeecg-boot-parent</artifactId>
+    <version>2.0.2</version>
+  </parent>
   <name>module-callback</name>
   <!-- FIXME change it to the project's website -->
   <url>http://www.example.com</url>
@@ -18,56 +22,102 @@
 
   <dependencies>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>4.11</version>
-      <scope>test</scope>
+      <groupId>cn.com.ctop</groupId>
+      <artifactId>module-common</artifactId>
+      <version>2.0.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <version>1.7.25</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.25</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jeecgframework.boot</groupId>
+      <artifactId>jeecg-boot-base-common</artifactId>
+      <version>2.0.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl-over-slf4j</artifactId>
+      <version>1.7.25</version>
+    </dependency>
+    <dependency>
+      <groupId>com.xuxueli</groupId>
+      <artifactId>xxl-mq-client</artifactId>
+      <version>1.2.2</version>
     </dependency>
   </dependencies>
 
   <build>
-    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
-      <plugins>
-        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
-        <plugin>
-          <artifactId>maven-clean-plugin</artifactId>
-          <version>3.1.0</version>
-        </plugin>
-        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
-        <plugin>
-          <artifactId>maven-resources-plugin</artifactId>
-          <version>3.0.2</version>
-        </plugin>
-        <plugin>
-          <artifactId>maven-compiler-plugin</artifactId>
-          <version>3.8.0</version>
-        </plugin>
-        <plugin>
-          <artifactId>maven-surefire-plugin</artifactId>
-          <version>2.22.1</version>
-        </plugin>
-        <plugin>
-          <artifactId>maven-jar-plugin</artifactId>
-          <version>3.0.2</version>
-        </plugin>
-        <plugin>
-          <artifactId>maven-install-plugin</artifactId>
-          <version>2.5.2</version>
-        </plugin>
-        <plugin>
-          <artifactId>maven-deploy-plugin</artifactId>
-          <version>2.8.2</version>
-        </plugin>
-        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
-        <plugin>
-          <artifactId>maven-site-plugin</artifactId>
-          <version>3.7.1</version>
-        </plugin>
-        <plugin>
-          <artifactId>maven-project-info-reports-plugin</artifactId>
-          <version>3.0.0</version>
-        </plugin>
-      </plugins>
-    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.mybatis.generator</groupId>
+        <artifactId>mybatis-generator-maven-plugin</artifactId>
+        <version>1.3.6</version>
+        <configuration>
+          <!-- 是否覆盖,true表示会替换生成的JAVA文件,false则不覆盖 -->
+          <overwrite>true</overwrite>
+        </configuration>
+        <dependencies>
+          <!--mysql驱动包-->
+          <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.45</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+      <plugin>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+    <resources>
+      <!-- 解决MyBatis配置文件引入问题 -->
+      <resource>
+        <directory>src/main/java</directory>
+        <includes>
+          <include>**/*.properties</include>
+          <include>**/*.xml</include>
+        </includes>
+        <!-- 是否替换资源中的属性-->
+        <filtering>true</filtering>
+      </resource>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
   </build>
+
+  <profiles>
+    <profile>
+      <id>dev</id>
+      <properties>
+        <!-- 环境标识,需要与配置文件的名称相对应 -->
+        <activatedProperties>dev</activatedProperties>
+      </properties>
+      <activation>
+        <!-- 默认环境 -->
+        <activeByDefault>true</activeByDefault>
+      </activation>
+    </profile>
+    <profile>
+      <id>test</id>
+      <properties>
+        <activatedProperties>test</activatedProperties>
+      </properties>
+    </profile>
+    <profile>
+      <id>prod</id>
+      <properties>
+        <activatedProperties>prod</activatedProperties>
+      </properties>
+    </profile>
+  </profiles>
 </project>

+ 23 - 0
module-callback/src/main/java/cn/com/ctop/callback/StartApplication.java

@@ -0,0 +1,23 @@
+package cn.com.ctop.callback;
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
+import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.spring.boot.autoconfigure.ShiroAnnotationProcessorAutoConfiguration;
+import org.apache.shiro.spring.boot.autoconfigure.ShiroAutoConfiguration;
+import org.apache.shiro.spring.boot.autoconfigure.ShiroBeanAutoConfiguration;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+
+@Slf4j
+@SpringBootApplication(exclude = {DynamicDataSourceAutoConfiguration.class,DruidDataSourceAutoConfigure.class,DataSourceAutoConfiguration.class,ShiroAnnotationProcessorAutoConfiguration.class, ShiroAutoConfiguration.class, ShiroBeanAutoConfiguration.class})
+@ComponentScan(basePackages = {"cn.com.ctop.callback"})
+@Configuration
+public class StartApplication {
+    public static void main(String[] args){
+        SpringApplication.run(StartApplication.class, args);
+    }
+}

+ 29 - 0
module-callback/src/main/java/cn/com/ctop/callback/config/XxlMqConf.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.callback.config;
+
+import com.xxl.mq.client.factory.impl.XxlMqSpringClientFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.stereotype.Component;
+
+@Component
+public class XxlMqConf {
+
+    // ---------------------- param ----------------------
+
+    @Value("${xxl.mq.admin.address}")
+    private String adminAddress;
+    @Value("${xxl.mq.accessToken}")
+    private String accessToken;
+
+
+    @Bean
+    public XxlMqSpringClientFactory getXxlMqConsumer(){
+
+        XxlMqSpringClientFactory xxlMqSpringClientFactory = new XxlMqSpringClientFactory();
+        xxlMqSpringClientFactory.setAdminAddress(adminAddress);
+        xxlMqSpringClientFactory.setAccessToken(accessToken);
+
+        return xxlMqSpringClientFactory;
+    }
+
+}

+ 28 - 0
module-callback/src/main/java/cn/com/ctop/callback/controller/CallbackController.java

@@ -0,0 +1,28 @@
+package cn.com.ctop.callback.controller;
+
+import com.xxl.mq.client.message.XxlMqMessage;
+import com.xxl.mq.client.producer.XxlMqProducer;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+@Controller
+@RequestMapping("/")
+public class CallbackController {
+    @RequestMapping("/{group}/{topic}")
+    @ResponseBody
+    public Result<String> callbackMethod(HttpServletRequest request,
+                                         HttpServletResponse response,
+                                         @PathVariable(name = "group") String group,
+                                         @PathVariable(name = "topic") String topic){
+        Result<String> result = new Result<>();
+        XxlMqProducer.produce(new XxlMqMessage(group+"_"+topic, request.getQueryString()));
+        result.success("success");
+        return result;
+    }
+}

+ 0 - 13
module-callback/src/main/java/org/jeecgframework/boot/App.java

@@ -1,13 +0,0 @@
-package org.jeecgframework.boot;
-
-/**
- * Hello world!
- *
- */
-public class App 
-{
-    public static void main( String[] args )
-    {
-        System.out.println( "Hello World!" );
-    }
-}

+ 13 - 0
module-callback/src/main/resources/application-dev.yml

@@ -0,0 +1,13 @@
+server:
+  port: 8801
+  servlet:
+    context-path: /
+xxl:
+  mq:
+    accessToken:
+    admin:
+      address: http://129.28.150.229:8808/xxl-mq-admin
+logging:
+  level:
+    root: info
+  config: classpath:logback-dev.xml

+ 13 - 0
module-callback/src/main/resources/application-prod.yml

@@ -0,0 +1,13 @@
+server:
+  port: 8801
+  servlet:
+    context-path: /
+xxl:
+  mq:
+    accessToken:
+    admin:
+      address: http://129.28.150.229:8808/xxl-mq-admin
+logging:
+  level:
+    root: info
+  config: classpath:logback-prod.xml

+ 13 - 0
module-callback/src/main/resources/application-test.yml

@@ -0,0 +1,13 @@
+server:
+  port: 8801
+  servlet:
+    context-path: /
+xxl:
+  mq:
+    accessToken:
+    admin:
+      address: http://129.28.150.229:8808/xxl-mq-admin
+logging:
+  level:
+    root: info
+  config: classpath:logback-test.xml

+ 8 - 0
module-callback/src/main/resources/application.yml

@@ -0,0 +1,8 @@
+server:
+  port: 8801
+  context-path: /
+xxl:
+  mq:
+    accessToken:
+    admin:
+      address: http://129.28.150.229:8808/xxl-mq-admin

+ 29 - 0
module-callback/src/main/resources/logback-dev.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration debug="false" scan="true" scanPeriod="1 seconds">
+
+    <contextName>logback</contextName>
+    <property name="log.path" value="/data/applogs/xxl-mq/xxl-mq-samples-springboot.log"/>
+
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
+        </rollingPolicy>
+        <encoder>
+            <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
+            </pattern>
+        </encoder>
+    </appender>
+
+    <root level="info">
+        <appender-ref ref="console"/>
+        <appender-ref ref="file"/>
+    </root>
+
+</configuration>

+ 29 - 0
module-callback/src/main/resources/logback-prod.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration debug="false" scan="true" scanPeriod="1 seconds">
+
+    <contextName>logback</contextName>
+    <property name="log.path" value="/data/applogs/xxl-mq/xxl-mq-samples-springboot.log"/>
+
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
+        </rollingPolicy>
+        <encoder>
+            <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
+            </pattern>
+        </encoder>
+    </appender>
+
+    <root level="info">
+        <appender-ref ref="console"/>
+        <appender-ref ref="file"/>
+    </root>
+
+</configuration>

+ 29 - 0
module-callback/src/main/resources/logback-test.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration debug="false" scan="true" scanPeriod="1 seconds">
+
+    <contextName>logback</contextName>
+    <property name="log.path" value="/data/applogs/xxl-mq/xxl-mq-samples-springboot.log"/>
+
+    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
+        </encoder>
+    </appender>
+
+    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${log.path}</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+            <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
+        </rollingPolicy>
+        <encoder>
+            <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
+            </pattern>
+        </encoder>
+    </appender>
+
+    <root level="info">
+        <appender-ref ref="console"/>
+        <appender-ref ref="file"/>
+    </root>
+
+</configuration>