Преглед на файлове

:recycle: 重构代码。 动态路由部分抽取成公用组件

冷冷 преди 6 години
родител
ревизия
e64d260712

+ 46 - 0
pigx-common/pigx-common-gateway/pom.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~
+  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
+  ~
+  ~  Redistribution and use in source and binary forms, with or without
+  ~  modification, are permitted provided that the following conditions are met:
+  ~
+  ~ Redistributions of source code must retain the above copyright notice,
+  ~  this list of conditions and the following disclaimer.
+  ~  Redistributions in binary form must reproduce the above copyright
+  ~  notice, this list of conditions and the following disclaimer in the
+  ~  documentation and/or other materials provided with the distribution.
+  ~  Neither the name of the pig4cloud.com developer nor the names of its
+  ~  contributors may be used to endorse or promote products derived from
+  ~  this software without specific prior written permission.
+  ~  Author: lengleng (wangiegie@gmail.com)
+  ~
+  -->
+
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+		 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>
+	<parent>
+		<groupId>com.pig4cloud</groupId>
+		<artifactId>pigx-common</artifactId>
+		<version>${pigx.version}</version>
+	</parent>
+
+	<artifactId>pigx-common-gateway</artifactId>
+	<packaging>jar</packaging>
+
+	<description>pigx gateway</description>
+
+	<dependencies>
+		<dependency>
+			<groupId>com.pig4cloud</groupId>
+			<artifactId>pigx-common-core</artifactId>
+			<version>${pigx.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.springframework.cloud</groupId>
+			<artifactId>spring-cloud-gateway-core</artifactId>
+		</dependency>
+	</dependencies>
+</project>

+ 37 - 0
pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/annotation/EnablePigxDynamicRoute.java

@@ -0,0 +1,37 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.common.gateway.annotation;
+
+import com.pig4cloud.pigx.common.gateway.configuration.DynamicRouteAutoConfiguration;
+import org.springframework.context.annotation.Import;
+
+import java.lang.annotation.*;
+
+/**
+ * @author lengleng
+ * @date 2018/11/5
+ * <p>
+ * 开启pigx 动态路由
+ */
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+@Inherited
+@Import(DynamicRouteAutoConfiguration.class)
+public @interface EnablePigxDynamicRoute {
+}

+ 33 - 0
pigx-common/pigx-common-gateway/src/main/java/com/pig4cloud/pigx/common/gateway/configuration/DynamicRouteAutoConfiguration.java

@@ -0,0 +1,33 @@
+/*
+ *    Copyright (c) 2018-2025, lengleng All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the pig4cloud.com developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: lengleng (wangiegie@gmail.com)
+ */
+
+package com.pig4cloud.pigx.common.gateway.configuration;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @author lengleng
+ * @date 2018/11/5
+ * <p>
+ * 动态路由配置类
+ */
+@Configuration
+@ComponentScan("com.pig4cloud.pigx.common.gateway.support")
+public class DynamicRouteAutoConfiguration {
+
+}

+ 1 - 1
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/support/DynamicRouteEndpoint.java

@@ -15,7 +15,7 @@
  * Author: lengleng (wangiegie@gmail.com)
  */
 
-package com.pig4cloud.pigx.gateway.support;
+package com.pig4cloud.pigx.common.gateway.support;
 
 import cn.hutool.json.JSONObject;
 import com.pig4cloud.pigx.common.core.util.R;

+ 2 - 2
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/support/DynamicRouteHandler.java

@@ -15,12 +15,12 @@
  * Author: lengleng (wangiegie@gmail.com)
  */
 
-package com.pig4cloud.pigx.gateway.support;
+package com.pig4cloud.pigx.common.gateway.support;
 
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import com.pig4cloud.pigx.common.core.constant.CommonConstant;
-import com.pig4cloud.pigx.gateway.support.vo.RouteDefinitionVo;
+import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.cloud.gateway.event.RefreshRoutesEvent;
 import org.springframework.cloud.gateway.filter.FilterDefinition;

+ 1 - 1
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/support/DynamicRouteInitEvent.java

@@ -15,7 +15,7 @@
  * Author: lengleng (wangiegie@gmail.com)
  */
 
-package com.pig4cloud.pigx.gateway.support;
+package com.pig4cloud.pigx.common.gateway.support;
 
 import org.springframework.context.ApplicationEvent;
 

+ 2 - 2
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/support/DynamicRouteInitRunner.java

@@ -15,10 +15,10 @@
  * Author: lengleng (wangiegie@gmail.com)
  */
 
-package com.pig4cloud.pigx.gateway.support;
+package com.pig4cloud.pigx.common.gateway.support;
 
 import com.pig4cloud.pigx.common.core.constant.CommonConstant;
-import com.pig4cloud.pigx.gateway.support.vo.RouteDefinitionVo;
+import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;

+ 2 - 2
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/support/RedisRouteDefinitionWriter.java

@@ -15,10 +15,10 @@
  * Author: lengleng (wangiegie@gmail.com)
  */
 
-package com.pig4cloud.pigx.gateway.support;
+package com.pig4cloud.pigx.common.gateway.support;
 
 import com.pig4cloud.pigx.common.core.constant.CommonConstant;
-import com.pig4cloud.pigx.gateway.support.vo.RouteDefinitionVo;
+import com.pig4cloud.pigx.common.gateway.vo.RouteDefinitionVo;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;

+ 2 - 1
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/support/vo/RouteDefinitionVo.java

@@ -15,7 +15,8 @@
  * Author: lengleng (wangiegie@gmail.com)
  */
 
-package com.pig4cloud.pigx.gateway.support.vo;
+package com.pig4cloud.pigx.common.gateway.vo
+	;
 
 import org.springframework.cloud.gateway.route.RouteDefinition;
 

+ 1 - 0
pigx-common/pom.xml

@@ -36,6 +36,7 @@
 		<module>pigx-common-cache</module>
 		<module>pigx-common-core</module>
 		<module>pigx-common-job</module>
+		<module>pigx-common-gateway</module>
 		<module>pigx-common-log</module>
 		<module>pigx-common-security</module>
 		<module>pigx-common-swagger</module>

+ 6 - 0
pigx-gateway/pom.xml

@@ -42,6 +42,12 @@
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-data-redis-reactive</artifactId>
 		</dependency>
+		<!--动态路由组件-->
+		<dependency>
+			<groupId>com.pig4cloud</groupId>
+			<artifactId>pigx-common-gateway</artifactId>
+			<version>${pigx.version}</version>
+		</dependency>
 		<!--配置中心客户端-->
 		<dependency>
 			<groupId>org.springframework.cloud</groupId>

+ 2 - 0
pigx-gateway/src/main/java/com/pig4cloud/pigx/gateway/PigxGatewayApplication.java

@@ -20,6 +20,7 @@
 package com.pig4cloud.pigx.gateway;
 
 
+import com.pig4cloud.pigx.common.gateway.annotation.EnablePigxDynamicRoute;
 import org.springframework.boot.SpringApplication;
 import org.springframework.cloud.client.SpringCloudApplication;
 
@@ -28,6 +29,7 @@ import org.springframework.cloud.client.SpringCloudApplication;
  * @date 2018年06月21日
  * 网关应用
  */
+@EnablePigxDynamicRoute
 @SpringCloudApplication
 public class PigxGatewayApplication {