实践网关之soul(2.0.1)

Soul是一个异步的,高性能的,跨语言的,响应式的API网关。我希望能够有一样东西像灵魂一样,保护您的微服务。参考了Kong,Spring-Cloud-Gateway等优秀的网关后,站在巨人的肩膀上,Soul由此诞生!

请求

选择器

http

Admin配置

divide selector

divide rule

get

header

1
2
3
4
module=test
method=test/findByUserId
rpcType=http
httpMethod=get

post

header

1
2
3
4
5
module=test
method=test/payment
rpcType=http
httpMethod=post
Content-Type=application/json

body

1
2
3
4
{
	"userName":"Ray",
	"userId":"1234"
}

dubbo

利用dubbo泛化调用实现

  • interfaceName:必填,请求的接口的全限定名。
  • method:必填,请求的方法。
  • 如果请求的方法的参数是primary类型,则
    • params:请求的参数类型和值,比如你的参数是一个String,Int 等。 如果是连续相同类型的参数,那么就要写成一个数组。
  • 如果请求参数是对象,比如自定义对象、java.util.Date、java.util.Map、java.util.List等
    • paramClass:对象全限定名数组。

    • classParams:对象值数组。

Admin配置

dubbo selector

dubbo rule

simple parameter

header

1
2
3
4
module=dubbo1
method=findById
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"findById",
	"params":{
        "java.lang.String":"abc"       
    }
}

DTO parameter

header

1
2
3
4
module=dubbo1
method=insert
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
8
9
10
11
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"insert",
    "paramClass":"[org.dromara.soul.test.dubbo.api.entity.DubboTest]",
    "classParams":[
        {
            "id":"xxxx",
            "name":"xiaoyu"
        }
    ]
}

DTO and simple parameter

header

1
2
3
4
module=dubbo1
method=insert3
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"insert3",
    "paramClass":"[org.dromara.soul.test.dubbo.api.entity.DubboTest]",
    "classParams":[
        {
            "id":"xxxx",
            "name":"xiaoyu"
        }
    ],
    "params":{
        "java.lang.String":[
            "aaa",
            "1bnbb"
        ]
    }
}

Map parameter

header

1
2
3
4
module=dubbo1
method=findByMapIdAndName
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
8
9
10
11
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"findByMapIdAndName",
    "paramClass":"[java.util.Map]",
    "classParams":[
        {
            "id":"xxxx",
            "name":"xiaoyu"
        }
    ]
}

List parameter

header

1
2
3
4
module=dubbo1
method=findByListIdAndName
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
8
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"findByMapIdAndName",
    "paramClass":"[java.util.List]",
    "classParams":[
        ["xxxx","xiaoyu"]
     ]
}

DTO and Map parameter

header

1
2
3
4
module=dubbo1
method=findByDtoMapIdAndName
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"findByDtoMapIdAndName",
    "paramClass":"[org.dromara.soul.test.dubbo.api.entity.DubboTest,java.util.Map]",
    "classParams":[
        {
            "id":"xxxx",
            "name":"xiaoyu"
        },
        {
            "id":"abc",
            "name":"cde"
        }
    ]
}

DTO and List parameter

header

1
2
3
4
module=dubbo1
method=findByDtoListIdAndName
rpcType=dubbo
Content-Type=application/json

body

1
2
3
4
5
6
7
8
9
10
11
12
{
    "interfaceName":"org.dromara.soul.test.dubbo.api.service.DubboTestService",
    "method":"findByDtoListIdAndName",
    "paramClass":"[org.dromara.soul.test.dubbo.api.entity.DubboTest,java.util.List]",
    "classParams":[
        {
            "id":"xxxx",
            "name":"xiaoyu"
        },
        ["xxxx","xiaoyu"]
    ]
}