Quick Start

Quick Start

Let’s quickly demonstrate Pixiu’s capabilities by converting an HTTP request to a Dubbo2 request.

Use Case

Pixiu converts the Client’s HTTP request into a Dubbo2 request, which is then forwarded to the Dubbo Server. It then converts the Dubbo Server’s response back into an HTTP response, finally returning it to the Client.

Architecture Diagram

Architecture

Example

The example path can be found at /samples/dubbogo/simple/resolve.

Dubbo Server Implementation and Startup

The Dubbo Server provides interfaces for adding, deleting, modifying, and querying users. The specific code implementations can be found in the server directory under the example path.

The configuration of the Dubbo Server is as follows, registering the Dubbo2 protocol interface com.dubbogo.pixiu.UserService.

  1. dubbo:
  2. registries:
  3. zk:
  4. protocol: zookeeper
  5. timeout: 3s
  6. address: 127.0.0.1:2181
  7. protocols:
  8. dubbo:
  9. name: dubbo
  10. port: 20000
  11. provider:
  12. registry-ids: zk
  13. services:
  14. UserProvider:
  15. group: test
  16. version: 1.0.0
  17. cluster: test_dubbo
  18. serialization: hessian2
  19. interface: com.dubbogo.pixiu.UserService

Pixiu Configuration and Startup

For the scenario of the use case, Pixiu needs to start the corresponding HTTP Listener to monitor HTTP requests, which will utilize httpconnectionmanager. Then, as it needs to convert HTTP requests into Dubbo requests, it requires dgp.filter.http.dubboproxy, where we set auto_resolve to true to enable the default HTTP to Dubbo conversion protocol (specific definitions can be found in the Appendix).

The specific configuration for Pixiu is as follows:

  1. static_resources:
  2. listeners:
  3. - name: "net/http"
  4. protocol_type: "HTTP"
  5. address:
  6. socket_address:
  7. address: "0.0.0.0"
  8. port: 8883
  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: ""

Client Implementation

The Client is a simple HTTP Client implementation but needs to populate corresponding data in the HTTP request’s Path and Header according to the aforementioned HTTP to Dubbo default conversion protocol, as shown below.

  1. url := "http://localhost:8883/UserService/com.dubbogo.pixiu.UserService/GetUserByName"
  2. data := "{\"types\":\"string\",\"values\":\"tc\"}"
  3. client := &http.Client{Timeout: 5 * time.Second}
  4. req, err := http.NewRequest("POST", url, strings.NewReader(data))
  5. req.Header.Set("x-dubbo-http1.1-dubbo-version", "1.0.0")
  6. req.Header.Set("x-dubbo-service-protocol", "dubbo")
  7. req.Header.Set("x-dubbo-service-version", "1.0.0")
  8. req.Header.Set("x-dubbo-service-group", "test")
  9. assert.NoError(t, err)
  10. req.Header.Add("Content-Type", "application/json")
  11. resp, err := client.Do(req)

Example Start

The project provides a quick start script, and the Go development environment should be installed locally.

  1. # cd to the main example directory
  2. cd samples/dubbogo/simple/
  3. # Prepare the environment, start zk, and prepare the corresponding configuration files
  4. ./start.sh prepare resolve
  5. # Start the dubbo server
  6. ./start.sh startServer resolve
  7. # Start Pixiu
  8. ./start.sh startPixiu resolve
  9. # Start Client test case
  10. ./start.sh startTest resolve
  11. # Or use curl
  12. curl -X POST 'http://localhost:8883/UserService/com.dubbogo.pixiu.UserService/GetUserByName' -d '{"types":"string","values":"tc"}' -H 'Content-Type: application/json' -H 'x-dubbo-http1.1-dubbo-version: 1.0.0' -H 'x-dubbo-service-protocol: dubbo' -H 'x-dubbo-service-version: 1.0.0' -H 'x-dubbo-service-group: test'
  13. # Response {"age":15,"code":1,"iD":"0001","name":"tc","time":"2021-08-01T18:08:41+08:00"}

Docker Example

  1. docker pull phial3/dubbo-go-pixiu:latest
  2. docker run --name pixiuname -p 8883:8883 \
  3. -v /yourpath/conf.yaml:/etc/pixiu/conf.yaml \
  4. -v /yourpath/log.yml:/etc/pixiu/log.yml \
  5. apache/dubbo-go-pixiu:latest
  6. # Start provider that uses zookeeper as the registration center first
  7. cd samples/dubbogo/simple/resolve/server
  8. # Add required environment variables, specifying the location of the provider's configuration file
  9. export DUBBO_GO_CONFIG_PATH="../profiles/dev/server.yml"
  10. export APP_LOG_CONF_FILE="../profiles/dev/log.yml"
  11. # Start provider
  12. go run server.go user.go
  13. # Go to the test directory and start the test example
  14. cd samples/dubbogo/simple/resolve/test
  15. go test pixiu_test.go

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)