Dubbo HttpFilter 介绍

Dubbo HttpFilter 介绍

使用 HTTP 调用 Dubbo

定义Pixiu配置文件

  1. static_resources:
  2. listeners:
  3. - name: "http-listener"
  4. protocol_type: "HTTP"
  5. address:
  6. socket_address:
  7. address: "0.0.0.0"
  8. port: 8888
  9. filter_chains:
  10. filters:
  11. - name: dgp.filter.httpconnectionmanager
  12. config:
  13. route_config:
  14. routes:
  15. - match:
  16. prefix: "*"
  17. http_filters:
  18. - name: dgp.filter.http.dubboproxy
  19. config:
  20. dubboProxyConfig:
  21. auto_resolve: true
  22. registries:
  23. "zookeeper":
  24. protocol: "zookeeper"
  25. timeout: "3s"
  26. address: "127.0.0.1:2181"
  27. username: ""
  28. password: ""
  29. timeout_config:
  30. connect_timeout: 5s
  31. request_timeout: 5s
  32. clusters:
  33. - name: "dubbo-server"
  34. lb_policy: "lb"
  35. endpoints:
  36. - id: 1
  37. socket_address:
  38. address: 127.0.0.1
  39. port: 20000
  40. shutdown_config:
  41. timeout: "60s"
  42. step_timeout: "10s"
  43. reject_policy: "immediacy"

准备Dubbo服务

启动zookeeper,需要提前准备好docker和compose,如果本地有的话可以忽略

docker-compose.yml

  1. docker-compose -f {CURRENT_PATH}/dubbo-go-pixiu-samples/dubbohttpproxy/docker/docker-compose.yml && docker-compose up -d

启动 Dubbo Server

Run

  1. export DUBBO_GO_CONFIG_PATH={CURRENT_PATH}/dubbo-go-pixiu-samples/dubbohttpproxy/server/dubbo/profiles/dev/server.yml
  2. go run .

启动 Pixiu

  1. ./dubbo-go-pixiu gateway start --config {CURRENT_PATH}pixiu/conf.yaml

使用 curl 来做查询和更新

使用以下命令运行命令 curl:

查询

  1. curl http://localhost:8888/UserService/com.dubbogo.pixiu.UserService/GetUserByName -X POST \
  2. -H 'Content-Type: application/json' \
  3. -H 'x-dubbo-http1.1-dubbo-version: 1.0.0' \
  4. -H 'x-dubbo-service-protocol: dubbo' \
  5. -H 'x-dubbo-service-version: 1.0.0' \
  6. -H 'x-dubbo-service-group: test' \
  7. -d '{"types":"string","values":"tc"}'

更新

  1. curl http://localhost:8888/UserService/com.dubbogo.pixiu.UserService/UpdateUserByName -X POST \
  2. -H 'Content-Type: application/json' \
  3. -H 'x-dubbo-http1.1-dubbo-version: 1.0.0' \
  4. -H 'x-dubbo-service-protocol: dubbo' \
  5. -H 'x-dubbo-service-version: 1.0.0' \
  6. -H 'x-dubbo-service-group: test' \
  7. -d '{"types":"string,object","values":["tc",{"id":"0001","code":1,"name":"tc","age":15}]}'

最后修改 September 13, 2024: Refactor website structure (#2860) (1a4b998f54b)