xyjboys opened a new issue, #604: URL: https://github.com/apache/dubbo-go-samples/issues/604
package client_dubbo import ( "context" "dubbo.apache.org/dubbo-go/v3/config" "dubbo.apache.org/dubbo-go/v3/config/generic" _ "dubbo.apache.org/dubbo-go/v3/imports" "dubbo.apache.org/dubbo-go/v3/protocol/dubbo" hessian "github.com/apache/dubbo-go-hessian2" "github.com/dubbogo/gost/log/logger" "github.com/gin-gonic/gin" ) const appName = "dubbo.io" func Call(c *gin.Context) { interfaceName := "com.zhouhx.api.UserService" zkUrl := "127.0.0.1:2181" methodName := "getUserInfo" vsersion := "1.0.0" group := "dubbo" paramsTypes := []string{"java.lang.String"} paramsValues := []hessian.Object{"测试数据"} dubboRefConf := newRefConf(interfaceName, zkUrl, dubbo.DUBBO, vsersion, group) var resp, err = dubboRefConf.GetRPCService().(*generic.GenericService).Invoke( context.TODO(), methodName, paramsTypes, paramsValues, ) if err != nil { panic(err) } logger.Infof("queryUsers(users []*User) res: %+v", resp) } func newRefConf(iface, zkUrl string, protocol string, version string, group string) config.ReferenceConfig { registryConfig := &config.RegistryConfig{ Protocol: "zookeeper", Address: zkUrl, RegistryType: "service", } metadataConf := &config.MetadataReportConfig{ Protocol: "zookeeper", Address: zkUrl, } refConf := config.ReferenceConfig{ InterfaceName: iface, Cluster: "failover", RegistryIDs: []string{"zk"}, Protocol: protocol, Version: version, Group: group, Generic: "true", } rootConfig := config.NewRootConfigBuilder(). AddRegistry("zk", registryConfig). SetMetadataReport(metadataConf). Build() if err := config.Load(config.WithRootConfig(rootConfig)); err != nil { panic(err) } _ = refConf.Init(rootConfig) refConf.GenericLoad(appName) return refConf } 这是一个dubbo-go 3.0的客户端样例,我发现在 3.0之前的客户端需要配将注册中心和 服务的配置写在配置文件里,但是我需要像3.0一样能 通过参数传的方式调用 java 2.7的服务 没有找个合适例子。 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org