Эх сурвалжийг харах

spring-cloud-gateway替换zuul

nnkwrik 6 жил өмнө
parent
commit
5234249b08

+ 69 - 0
gateway/pom.xml

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         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>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.1.1.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>io.github.nnkwrik</groupId>
+    <artifactId>gateway</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>gateway</name>
+    <description>Demo project for Spring Boot</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <spring-cloud.version>Greenwich.RC1</spring-cloud.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-gateway</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+    <repositories>
+        <repository>
+            <id>spring-milestones</id>
+            <name>Spring Milestones</name>
+            <url>https://repo.spring.io/milestone</url>
+        </repository>
+    </repositories>
+
+</project>

+ 16 - 0
gateway/src/main/java/io/github/nnkwrik/gateway/GatewayApplication.java

@@ -0,0 +1,16 @@
+package io.github.nnkwrik.gateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
+
+@SpringBootApplication
+@EnableEurekaClient
+public class GatewayApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(GatewayApplication.class, args);
+    }
+
+}
+

+ 63 - 0
gateway/src/main/resources/application.yml

@@ -0,0 +1,63 @@
+server:
+  port: 8080
+eureka:
+  client:
+    service-url:
+      defaultZone: http://localhost:8801/eureka/
+
+spring:
+  application:
+    name: cloud-gateway
+  cloud:
+    gateway:
+      discovery:
+        locator:
+          enabled: true
+      routes:
+
+      - id: auth
+        uri: lb://AUTH-SERVICE
+        predicates:
+        - Path=/auth/**
+
+      - id: chat
+        uri: lb://IM-SERVICE
+        predicates:
+        - Path=/chat/**
+      - id: ws
+        uri: lb:ws://IM-SERVICE #websocket
+        predicates:
+        - Path=/ws/**
+
+      - id: index
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/index/**
+      - id: goods
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/goods/**
+      - id: catalog
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/catalog/**
+      - id: catalog
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/catalog/**
+      - id: search
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/search/**
+      - id: post
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/post/**
+      - id: goodsUser
+        uri: lb://GOODS-SERVICE
+        predicates:
+        - Path=/goodsUser/**
+
+logging:
+  level:
+    org.springframework.cloud.gateway: debug

+ 8 - 0
gateway/src/main/resources/banner.txt

@@ -0,0 +1,8 @@
+   __   __  __  ____      __      ___
+ /'_ `\/\ \/\ \/\_ ,`\  /'__`\   / __`\
+/\ \L\ \ \ \_\ \/_/  /_/\ \L\.\_/\ \L\ \
+\ \____ \ \____/ /\____\ \__/.\_\ \____/
+ \/___L\ \/___/  \/____/\/__/\/_/\/___/
+   /\____/
+   \_/__/     ${AnsiColor.YELLOW}:: 一款仿闲鱼开源交易平台 ::
+             ${AnsiColor.BLUE}GitHub : nnkwrik/fangxianyu

+ 17 - 0
gateway/src/test/java/io/github/nnkwrik/gateway/GatewayApplicationTests.java

@@ -0,0 +1,17 @@
+package io.github.nnkwrik.gateway;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class GatewayApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}
+