Skip to content

Commit

Permalink
http2rpc support paramFromEntireBody
Browse files Browse the repository at this point in the history
  • Loading branch information
sjtuzbk committed Dec 21, 2023
1 parent 3cd5bae commit 9d71a71
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ custom_edit_url: https://github.com/higress-group/higress-group.github.io/blob/m
| headersAttach | string | 需要透传的http headers | 1、空: 不设置表示不透传任何值;<br />2、*: 表示透传所有headers;<br /> 3、用英文逗号隔开需要透出的headers key: header-A,header-B,header-C,<br />|
| httpPath | string | 指定绑定serviceMethod的http-path | 例:"/dubbo/hello" |
| params | list of spec.dubbo.methods.params | 指定参数提取方式 | |
| paramFromEntireBody | ParamFromEntireBody | 指定将整个请求body作为参数,如果同时配置了paramFromEntireBody和params,params字段的内容将被忽略 | |

### spec.dubbo.methods.params
| 字段 | 类型 | 说明 | |
Expand All @@ -30,6 +31,11 @@ custom_edit_url: https://github.com/higress-group/higress-group.github.io/blob/m
| paramSource | PARAM_SOURCE_TYPE | 参数来源 | "QUERY" |
| paramType | string | Dubbo方法入参的参数类型 | "java.lang.String" |

### spec.dubbo.methods.paramFromEntireBody
| 字段 | 类型 | 说明 | |
| ----------- | --------------------------- | ----------- | ----------- |
| paramType | string | Dubbo方法入参的参数类型 | "java.lang.String" |

### HTTP_METHOD_TYPE
|| 说明 |
| ----------- | -------------------- |
Expand Down
32 changes: 32 additions & 0 deletions i18n/zh-cn/docusaurus-plugin-content-docs/current/user/dubbo.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,37 @@ $curl "localhost/dubbo/hello?p=abc"
{"result":"Service [name :demoService , port : 20880] sayName(\"abc\") : Hello,abc"}
```

## 将整个请求body作为方法参数
Http2Rpc支持将整个请求body序列化为Dubbo方法的入参,如下所示:

```yaml
apiVersion: networking.higress.io/v1
kind: Http2Rpc
metadata:
name: httproute-http2rpc-demo
namespace: higress-system
spec:
dubbo:
service: com.alibaba.nacos.example.dubbo.service.DemoService
version: 1.0.0
group: dev
methods:
- serviceMethod: sayName
headersAttach: "*"
httpMethods:
- "POST"
httpPath: "/dubbo/hello"
paramFromEntireBody:
paramType: "java.lang.String"
```
通过paramFromEntireBody字段,即可将整个请求body序列化为Dubbo方法的入参。参数的类型通过paramFromEntireBody.paramType字段来指定。该场景适用于Dubbo方法只有一个参数的情况,如果同时指定了paramFromEntireBody和params,params字段的内容将被忽略。
通过以上配置,我们可以执行以下命令来调用dubbo服务,注意请求的body必须符合json格式:
```bash
$curl "localhost/dubbo/hello" -X POST -d '"abc"'
{"result":"Service [name :demoService , port : 20880] sayName(\"abc\") : Hello,abc"}
```


## 配置参考
Http2Rpc的相关配置项参考[HTTP转Dubbo配置说明](./dubbo-http2rpc.md)

0 comments on commit 9d71a71

Please sign in to comment.