Soul网关源码阅读01-网关入门

Soul 网关入门:

 

Soul 文档:https://dromara.org

Soul 源码:https://github.com/dromara/soul

 

1、clone fork的源码

git  clone  https://github.com/dromara/soul.git

2、编译,编译完成大概需要2分多钟:

soul  git:(master) mvn clean package install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true -Dcheckstyle.skip=true


[INFO] soul-dist .......................................... SUCCESS [ 13.123 s]

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time:  02:20 min

[INFO] Finished at: 2021-01-14T09:15:52+08:00

[INFO] ------------------------------------------------------------------------

3、启动 Soul Admin,访问:http://127.0.0.1:9095/  进行登录

  • 配置数据库信息:soul/soul-admin/src/main/resources/application-local.yml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/soul?useUnicode=true&characterEncoding=utf-8
    username: root
    password:
    driver-class-name: com.mysql.jdbc.Driver
  • 启动服务:

2021-01-14 09:28:00.768  INFO 70856 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9095 (http) with context path ''

2021-01-14 09:28:00.780  INFO 70856 --- [           main] o.dromara.soul.admin.SoulAdminBootstrap  : Started SoulAdminBootstrap in 8.475 seconds (JVM running for 9.582)

2021-01-14 09:28:44.881  INFO 70856 --- [0.0-9095-exec-1] o.apache.tomcat.util.http.parser.Cookie  : A cookie header was received [1593338162] that contained an invalid cookie. That cookie will be ignored.

 Note: further occurrences of this error will be logged at DEBUG level.

2021-01-14 09:28:44.892  INFO 70856 --- [0.0-9095-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'

2021-01-14 09:28:44.892  INFO 70856 --- [0.0-9095-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'

2021-01-14 09:28:44.920  INFO 70856 --- [0.0-9095-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 28 ms

2021-01-14 10:10:12.814  INFO 70856 --- [0.0-9095-exec-6] o.d.s.a.l.websocket.WebsocketCollector   : websocket on open successful....

4、启动 Soul Bootstrap 网关服务

  • 配置soul admin 服务地址:soul/soul-bootstrap/src/main/resources/application-local.yml

soul :
    sync:
        websocket :
             urls: ws://localhost:9095/websocket
  • 启动成功:

2021-01-14 10:10:09.877  INFO 79791 --- [           main] o.d.s.w.configuration.SoulConfiguration  : load plugin:[response] [org.dromara.soul.plugin.alibaba.dubbo.response.DubboResponsePlugin]

2021-01-14 10:10:10.126  INFO 79791 --- [           main] b.s.s.d.w.WebsocketSyncDataConfiguration : you use websocket sync soul data.......

2021-01-14 10:10:12.755  INFO 79791 --- [           main] o.d.s.p.s.d.w.WebsocketSyncDataService   : websocket connection is successful.....

2021-01-14 10:10:13.028  INFO 79791 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'

2021-01-14 10:10:14.777  INFO 79791 --- [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 9195
  • 访问:http://127.0.0.1:9195/ ,返回如下结果

{

    "code": -107,

    "message": "Can not find selector, please check your configuration!",

    "data": null

}

5、启动:soul-examples 下的 soul-examples-http 

  • 添加配置soul admin 服务地址:soul-examples-http/src/main/resources/application.yml

soul:
  http:
    adminUrl: http://localhost:9095
    port: 8188
    contextPath: /http
    appName: http
    full: false
  • 把需要注册到网关的接口,增加注解:@SoulSpringMvcClient,服务启动后会将接口信息注册到网关soul admin

2021-01-14 17:06:31.284  INFO 20115 --- [pool-1-thread-1] s.c.s.i.SpringMvcClientBeanPostProcessor : http client register success :{} {"appName":"http","context":"/http","path":"/http/order/path/**/name","pathDesc":"","rpcType":"http","host":"192.168.2.1","port":8188,"ruleName":"/http/order/path/**/name","enabled":true,"registerMetaData":false}

2021-01-14 17:06:31.308  INFO 20115 --- [pool-1-thread-1] s.c.s.i.SpringMvcClientBeanPostProcessor : http client register success :{} {"appName":"http","context":"/http","path":"/http/order/findById","pathDesc":"Find by id","rpcType":"http","host":"192.168.2.1","port":8188,"ruleName":"/http/order/findById","enabled":true,"registerMetaData":false}

6、测试

  • 访问服务本身接口:http://127.0.0.1:8188/order/findById?id=1

  • 返回结果:

{

    "id": "1",

    "name": "hello world findById"

}
  • 通过soul网关进行访问:http://127.0.0.1:9195/http/order/findById?id=1

  • 返回结果:

{

    "id": "1",

    "name": "hello world findById"

}
  • 在Soul Bootstrap服务的控制台可以看到网关对服务请求的实际转发信息

2021-01-14 18:18:07.155  INFO 24406 --- [-work-threads-1] o.d.soul.plugin.base.AbstractSoulPlugin  : divide selector success match , selector name :/http

2021-01-14 18:18:07.156  INFO 24406 --- [-work-threads-1] o.d.soul.plugin.base.AbstractSoulPlugin  : divide selector success match , selector name :/http/order/findById

2021-01-14 18:18:07.172  INFO 24406 --- [-work-threads-1] o.d.s.plugin.httpclient.WebClientPlugin  : you request,The resulting urlPath is :http://192.168.2.1:8188/order/findById?id=1, retryTimes: 0

2021-01-14 18:18:07.404  WARN 24406 --- [-work-threads-1] io.netty.bootstrap.Bootstrap             : Unknown channel option 'SO_TIMEOUT' for channel '[id: 0x941669fe]'

注意:

在Soul Admin管理后台配置或更改插件信息后,Soul Bootstrap 和 Soul Admin 暂时不支持插件修改的自动加载。需要手动重启。

 

接下来将结合divde插件,发起http请求soul网关,阅读源码执行过程。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值