tree: e77584ba4dd10e59b82d36db72984b6a76cc1d77 [path history] [tgz]
  1. go-client/
  2. go-server/
  3. README.md
  4. README_zh.md
async/README.md

Async Sample

Background

Dubbo-go provides not only synchronous invocation, but also asynchronous invocation on the consumer side. In order to use it, the client needs to implement the following interface to asynchronously receive the response from the service provider:

type AsyncCallbackService interface {
    CallBack(response CallbackResponse) // callback
}

Example

Code

type UserProvider struct {
    GetUser func (ctx context.Context, req []interface{}, rsp *User) error
}

func (u *UserProvider) CallBack(res common.CallbackResponse) {
    fmt.Println("CallBack res:", res)
}

Configuration

Besides, client also needs to config “async:true” in consumer's yaml config file as following:

# reference config
references:
  "UserProvider":
    registry: "demoZk"
    protocol: "dubbo"
    interface: "org.apache.dubbo.UserProvider"
    # this is necessary to enable async call
    async: true

Pls. refer to HOWTO.md under the root directory to run this sample.