In the development and testing environment, it is often necessary to bypass the registry and test the designated service provider, which may require point-to-point direct connection. The point-to-point direct connection method will be based on the service interface and ignore the list of providers in the registry. Interface A is configured point-to-point and does not affect interface B to get the list from the registry.
This example provides the Consumer
point-to-point direct connection Provider
based on Dubbo-Go to complete service calls to help better understand the connectivity of Dubbo-Go.
├── go-client │ ├── cmd │ ├── conf │ └── pkg └── go-server ├── cmd ├── conf ├── docker ├── pkg └── tests └── integration
Direct example code description:
services: "UserProvider": registry: "demoZk" protocol : "dubbo" interface : "org.apache.dubbo.UserProvider" loadbalance: "random" warmup: "100" cluster: "failover" methods: - name: "GetUser" retries: 1 loadbalance: "random"
hessian.RegisterPOJO(&pkg.User{})
config.Load()
initSignal()
Based on the hessian
serialization protocol, using apache/dubbo-go-hessian2 RegisterPOJO register a POJO
Dubbo Init: Registration service, See apache/dubbo-go/../config_loader.go
Init Signal :
func initSignal() { signals := make(chan os.Signal, 1) // It is not possible to block SIGKILL or syscall.SIGSTOP signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals logger.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() default: time.AfterFunc(time.Duration(survivalTimeout), func() { logger.Warnf("app exit now by force...") os.Exit(1) }) // The program exits normally or timeout forcibly exits. fmt.Println("provider app exit now...") return } } }
dubbo service
you need to subscribe to at the beginning of the program startup. Make sure that the configuration file client.yml has been configured with the relevant information of the subscription service, and the service properties can be customized to override the configuration of the Provider's properties. Retain minimum configuration application
and references
verification point-to-point direct connection effect, no need to configure the registry.var userProvider = new(pkg.UserProvider)
func init() {
config.SetConsumerService(userProvider)
hessian.RegisterPOJO(&pkg.User{})
}
application: organization: "dubbo.io" name: "UserInfoClient" module: "dubbo-go user-info client" version: "0.0.1" environment: "dev" references: "UserProvider": registry: "demoZk" protocol: "dubbo" interface: "org.apache.dubbo.UserProvider" cluster: "failover" # this is necessary to enable direct-invoking. url: "dubbo://127.0.0.1:20000" methods: - name: "GetUser" retries: 3
If u wanna invoke a gRPC provider's service, pls change the url from “dubbo://127.0.0.1:20000” to “grpc://127.0.0.1:20000”.
hessian.RegisterPOJO(&pkg.User{})
config.Load()
user := &pkg.User{}
err := userProvider.GetUser(context.TODO(), []interface{}{"A001"}, user)
Refer to HOWTO.md under the root directory to run this sample.
Configure the environment variable to specify the configuration file path required for the service to load.
APP_LOG_CONF_FILE=direct/go-server/conf/log.yml; CONF_PROVIDER_FILE_PATH=direct/go-server/conf/server.yml
APP_LOG_CONF_FILE=direct/go-client/conf/log.yml; CONF_CONSUMER_FILE_PATH=direct/go-client/conf/client.yml
This example uses ZooKeeper as the registry, so you can run the Docker ZooKeeper environment directly. See docker-compose.yml
Refer to HOWTO.md under the root directory to run this sample.