dubbo-proxy

Description

dubbo-proxy plugin allows you proxy HTTP request to dubbo.

Requirement

If you are using OpenResty, you need to build it with dubbo support, see how to build

Runtime Attributes

NameTypeRequirementDefaultValidDescription
service_namestringrequireddubbo provider service name
service_versionstringrequireddubbo provider service version
methodstringoptionalthe path of uridubbo provider service method

Static Attributes

NameTypeRequirementDefaultValidDescription
upstream_multiplex_countnumberrequired32>= 1the maximum number of multiplex requests in an upstream connection

How To Enable

First of all, enable the dubbo-proxy plugin in the config.yaml:

  1. # Add this in config.yaml
  2. plugins:
  3. - ... # plugin you need
  4. - dubbo-proxy

Then reload APISIX.

Here’s an example, enable the dubbo-proxy plugin on the specified route:

  1. curl http://127.0.0.1:9080/apisix/admin/upstreams/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "nodes": {
  4. "127.0.0.1:20880": 1
  5. },
  6. "type": "roundrobin"
  7. }'
  8. curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  9. {
  10. "uris": [
  11. "/hello"
  12. ],
  13. "plugins": {
  14. "dubbo-proxy": {
  15. "service_name": "org.apache.dubbo.sample.tengine.DemoService",
  16. "service_version": "0.0.0",
  17. "method": "tengineDubbo"
  18. }
  19. },
  20. "upstream_id": 1
  21. }'

Test Plugin

You can follow the Quick Start example in Tengine and use the configuration above to test it. They should provide the same result.

The returned data from upstream dubbo service must be a Map<String, String>.

If the returned data is

  1. {
  2. "status": "200",
  3. "header1": "value1",
  4. "header2": "valu2",
  5. "body": "blahblah"
  6. }

the converted HTTP response will be

  1. HTTP/1.1 200 OK # "status" will be the status code
  2. ...
  3. header1: value1
  4. header2: value2
  5. ...
  6. blahblah # "body" will be the body

Disable Plugin

When you want to disable the dubbo-proxy plugin on a route/service, it is very simple, you can delete the corresponding json configuration in the plugin configuration, no need to restart the service, it will take effect immediately:

  1. $ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "methods": ["GET"],
  4. "uris": [
  5. "/hello"
  6. ],
  7. "plugins": {
  8. },
  9. "upstream_id": 1
  10. }
  11. }'

The dubbo-proxy plugin has been disabled now. It works for other plugins.

If you want to disable dubbo-proxy plugin totally, you need to comment out in the config.yaml:

  1. plugins:
  2. - ... # plugin you need
  3. #- dubbo-proxy

And then reload APISIX.