This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 804bc6e  feat: add polaris test (#306)
804bc6e is described below

commit 804bc6e6625797dff0147aad8711bf470f55b9f5
Author: liaochuntao <[email protected]>
AuthorDate: Mon Dec 6 19:14:35 2021 +0800

    feat: add polaris test (#306)
    
    Co-authored-by: springliao <[email protected]>
---
 registry/polaris/go-client/cmd/main.go       |  80 ++++++++++++++++++++
 registry/polaris/go-client/conf/dubbogo.yaml |  15 ++++
 registry/polaris/go-server/cmd/server.go     | 109 +++++++++++++++++++++++++++
 registry/polaris/go-server/conf/dubbogo.yaml |  26 +++++++
 4 files changed, 230 insertions(+)

diff --git a/registry/polaris/go-client/cmd/main.go 
b/registry/polaris/go-client/cmd/main.go
new file mode 100644
index 0000000..5a1b4fc
--- /dev/null
+++ b/registry/polaris/go-client/cmd/main.go
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+       "context"
+       "os"
+       "time"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/common/logger"
+       "dubbo.apache.org/dubbo-go/v3/config"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+
+       hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+type UserProviderWithCustomGroupAndVersion struct {
+       GetUser func(ctx context.Context, req *User) (rsp *User, err error)
+}
+
+type UserProvider struct {
+       GetUser func(ctx context.Context, req *User) (rsp *User, err error)
+}
+
+type User struct {
+       ID   string
+       Name string
+       Age  int32
+       Time time.Time
+}
+
+func (u *User) JavaClassName() string {
+       return "org.apache.dubbo.User"
+}
+
+func main() {
+       var userProvider = &UserProvider{}
+       var userProviderWithCustomRegistryGroupAndVersion = 
&UserProviderWithCustomGroupAndVersion{}
+       config.SetConsumerService(userProvider)
+       config.SetConsumerService(userProviderWithCustomRegistryGroupAndVersion)
+       hessian.RegisterPOJO(&User{})
+       err := config.Load()
+       if err != nil {
+               panic(err)
+       }
+
+       logger.Infof("\n\n\nstart to test dubbo")
+       user, err := userProvider.GetUser(context.TODO(), &User{Name: 
"Alex001"})
+       if err != nil {
+               logger.Errorf("error: %v\n", err)
+               os.Exit(1)
+               return
+       }
+       logger.Infof("response result: %v\n", user)
+
+       user, err = 
userProviderWithCustomRegistryGroupAndVersion.GetUser(context.TODO(), 
&User{Name: "Alex001"})
+       if err != nil {
+               logger.Errorf("error: %v\n", err)
+               os.Exit(1)
+               return
+       }
+       logger.Infof("response result: %v\n", user)
+}
diff --git a/registry/polaris/go-client/conf/dubbogo.yaml 
b/registry/polaris/go-client/conf/dubbogo.yaml
new file mode 100644
index 0000000..d7fd85a
--- /dev/null
+++ b/registry/polaris/go-client/conf/dubbogo.yaml
@@ -0,0 +1,15 @@
+dubbo:
+  registries:
+    polarisMesh:
+      protocol: polaris
+      address: 127.0.0.1:8091
+      namespace: default
+  consumer:
+    references:
+      UserProvider:
+        protocol: dubbo
+        interface: org.apache.dubbo.UserProvider.Test
+      UserProviderWithCustomGroupAndVersion:
+        protocol: dubbo
+        interface: org.apache.dubbo.UserProvider.Test2
+        version: myInterfaceVersion # dubbo interface version must be same 
with server
\ No newline at end of file
diff --git a/registry/polaris/go-server/cmd/server.go 
b/registry/polaris/go-server/cmd/server.go
new file mode 100644
index 0000000..1da04ab
--- /dev/null
+++ b/registry/polaris/go-server/cmd/server.go
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+       "context"
+       "fmt"
+       "os"
+       "os/signal"
+       "syscall"
+       "time"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/common/logger"
+       "dubbo.apache.org/dubbo-go/v3/config"
+       _ "dubbo.apache.org/dubbo-go/v3/imports"
+
+       hessian "github.com/apache/dubbo-go-hessian2"
+)
+
+var (
+       survivalTimeout = int(3e9)
+)
+
+func init() {
+       config.SetProviderService(&UserProvider{})
+       config.SetProviderService(&UserProviderWithCustomGroupAndVersion{})
+       // ------for hessian2------
+       hessian.RegisterPOJO(&User{})
+}
+
+type User struct {
+       ID   string
+       Name string
+       Age  int32
+       Time time.Time
+}
+
+type UserProvider struct {
+}
+
+func (u *UserProvider) GetUser(ctx context.Context, req *User) (*User, error) {
+       logger.Infof("req:%#v", req)
+       rsp := User{"A001", "Alex Stocks", 18, time.Now()}
+       logger.Infof("rsp:%#v", rsp)
+       return &rsp, nil
+}
+
+func (u *User) JavaClassName() string {
+       return "org.apache.dubbo.User"
+}
+
+type UserProviderWithCustomGroupAndVersion struct {
+}
+
+func (u *UserProviderWithCustomGroupAndVersion) GetUser(ctx context.Context, 
req *User) (*User, error) {
+       logger.Infof("req:%#v", req)
+       rsp := User{"A001", "Alex Stocks from 
UserProviderWithCustomGroupAndVersion", 18, time.Now()}
+       logger.Infof("rsp:%#v", rsp)
+       return &rsp, nil
+}
+
+// need to setup environment variable "CONF_PROVIDER_FILE_PATH" to 
"conf/server.yml" before run
+func main() {
+       if err := config.Load(); err != nil {
+               panic(err)
+       }
+
+       initSignal()
+}
+
+func initSignal() {
+       signals := make(chan os.Signal, 1)
+       // It is not possible to block SIGKILL or syscall.SIGSTOP
+       signal.Notify(signals, os.Interrupt, 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
+               }
+       }
+}
diff --git a/registry/polaris/go-server/conf/dubbogo.yaml 
b/registry/polaris/go-server/conf/dubbogo.yaml
new file mode 100644
index 0000000..06fd8fb
--- /dev/null
+++ b/registry/polaris/go-server/conf/dubbogo.yaml
@@ -0,0 +1,26 @@
+dubbo:
+  application:
+    name: myApp # metadata: application=myApp; name=myApp
+    module: opensource #metadata: module=opensource
+    group: myAppGroup # no metadata record
+    organization: dubbo # metadata: organization=dubbo
+    owner: laurence # metadata: owner=laurence
+    version: myversion # metadata: app.version=myversion
+    environment: pro # metadata: environment=pro
+  registries:
+    polarisMesh:
+      protocol: polaris
+      address: 127.0.0.1:8091
+      namespace: default
+  protocols:
+    dubbo:
+      name: dubbo
+      port: 20000
+  provider:
+    services:
+      UserProvider:
+        interface: org.apache.dubbo.UserProvider.Test
+      UserProviderWithCustomGroupAndVersion:
+        interface: org.apache.dubbo.UserProvider.Test2
+        version: myInterfaceVersion # dubbo interface version must be same 
with client
+        group: myInterfaceGroup # dubbo interface group must be same with 
client
\ No newline at end of file

Reply via email to