async/

directory
v1.5.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2022 License: Apache-2.0

README

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.

Directories

Path Synopsis
go-client
cmd command
pkg
go-server
cmd command
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL