feat:first commit gateway
This commit is contained in:
@@ -17,4 +17,12 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.xiang</groupId>
|
||||
<artifactId>xs-service</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -2,12 +2,14 @@ package com.xiang;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
|
||||
/**
|
||||
* @Author: xiang
|
||||
* @Date: 2025-08-12 17:26
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
|
||||
public class XsGatewayApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XsGatewayApplication.class, args);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.xiang.xservice.gateway.server.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class ServiceDiscoveryController {
|
||||
@Autowired
|
||||
private DiscoveryClient discoveryClient;
|
||||
|
||||
/**
|
||||
* 查看所有注册到 Nacos 的服务
|
||||
*/
|
||||
@GetMapping("/services")
|
||||
public List<String> getServices() {
|
||||
return discoveryClient.getServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看某个服务的实例信息
|
||||
*/
|
||||
@GetMapping("/services/instances")
|
||||
public Object getServiceInstances(String serviceName) {
|
||||
return discoveryClient.getInstances(serviceName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
server:
|
||||
port: 38010
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: xservice-gateway
|
||||
main:
|
||||
web-application-type: reactive # 强制使用 WebFlux
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: general.xiangtech.xyz:8848
|
||||
namespace: 00131110-3ecb-4a35-8bbb-624edde1d937
|
||||
group: DEFAULT_GROUP
|
||||
username: nacos
|
||||
password: nacos
|
||||
gateway:
|
||||
discovery:
|
||||
locator:
|
||||
enabled: true # 开启 nacos 自动路由
|
||||
routes:
|
||||
- id: xservice-auth-center
|
||||
uri: lb://xservice-auth-center
|
||||
predicates:
|
||||
- Path=/api-auth/**
|
||||
filters:
|
||||
- StripPrefix=1
|
||||
|
||||
redis:
|
||||
host: r-bp1wt59a6nfyt4e3ltpd.redis.rds.aliyuncs.com
|
||||
port: 6379
|
||||
password: Xiang0000 # 如果无密码可以省略
|
||||
database: 0
|
||||
timeout: 5000
|
||||
lettuce:
|
||||
pool:
|
||||
max-active: 8
|
||||
max-idle: 8
|
||||
min-idle: 0
|
||||
max-wait: 1000
|
||||
@@ -3,4 +3,6 @@ server:
|
||||
|
||||
spring:
|
||||
profiles:
|
||||
active: local
|
||||
active: local
|
||||
main:
|
||||
web-application-type: reactive
|
||||
Reference in New Issue
Block a user