栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

路由网关Gateway

路由网关Gateway

本节内容

加入网关gateway

新建网关模块

pom,注册中心看情况


	com.alibaba.cloud
	spring-cloud-starter-alibaba-nacos-discovery


	org.springframework.cloud
	spring-cloud-starter-gateway

配置文件

server:
  port: ${port:9001}
spring:
  application:
    name: gateway
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
    gateway:
      discovery:
        locator:
          enabled: true    # 开启动态路由
      routes:
        - id: producer  # 唯一标识
          uri: lb://producer   # lb://负载均衡,producer服务名
          predicates:   # 路由判断,不符合的不路由
            - Path=/p

        - id: consumer
          uri: lb://consumer
          predicates:
            - Path=/c

启动类

@SpringBootApplication
@EnableDiscoveryClient
public class App {
	public static void main(String[] args) {
		SpringApplication.run(App.class);
	}
}
测试

消费者http://localhost:9001/c

生产者http://localhost:9001/p?age=3

成功!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/701577.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号