diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69e4992..c5861d0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,6 +51,11 @@ jobs: - name: Check out code uses: actions/checkout@v1 + - name: Install docker-compose + run: | + sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + - name: Start Zookeeper Docker Compose run: docker-compose -f docker-compose-zk.yml up -d @@ -60,6 +65,13 @@ jobs: - name: Start Etcd Docker Compose run: docker-compose -f docker-compose-etcd.yml up -d + - name: Check Consul Logs + run: | + docker-compose -f docker-compose-consul.yml logs consul1 + docker-compose -f docker-compose-consul.yml logs consul2 + docker-compose -f docker-compose-consul.yml logs consul3 + docker-compose -f docker-compose-consul.yml logs consul4 + - name: Run Unit tests. run: | go test `go list ./... | grep example` -coverprofile=coverage.txt -covermode=atomic diff --git a/clients/http_client_factory.go b/clients/http_client_factory.go index 038f21e..3869b94 100644 --- a/clients/http_client_factory.go +++ b/clients/http_client_factory.go @@ -68,6 +68,7 @@ func RegisterMetaData(adminTokenData model.AdminTokenData, metaData *model.MetaD params["contextPath"] = metaData.ContextPath params["host"] = metaData.Host params["port"] = metaData.Port + params["namespaceId"] = metaData.NamespaceId if metaData.RPCType != "" { params["rpcType"] = metaData.RPCType @@ -107,6 +108,7 @@ func UrlRegister(adminTokenData model.AdminTokenData, urlMetaData *model.URIRegi params["host"] = urlMetaData.Host params["port"] = urlMetaData.Port params["rpcType"] = urlMetaData.RPCType + params["namespaceId"] = urlMetaData.NamespaceId tokenRequest := initShenYuCommonRequest(headers, params, constants.REGISTER_URI, "") diff --git a/clients/nacos_client/nacos_client.go b/clients/nacos_client/nacos_client.go index bfd949f..f4b62dd 100644 --- a/clients/nacos_client/nacos_client.go +++ b/clients/nacos_client/nacos_client.go @@ -42,7 +42,7 @@ type ShenYuNacosClient struct { type NacosClientParam struct { IpAddr string //the nacos server address require user provide Port uint64 //the nacos server port require user provide - NamespaceId string // the namespaceId of Nacos.When namespace is public, fill in the blank string here require user provide. + NamespaceId string //the namespaceId of Nacos require user provide. } /** diff --git a/docker-compose-consul.yml b/docker-compose-consul.yml index 1e1230a..d9fd86f 100644 --- a/docker-compose-consul.yml +++ b/docker-compose-consul.yml @@ -17,7 +17,7 @@ version: "3.1" services: consul1: - image: consul:latest + image: consul:1.13.9 container_name: consul1 restart: always networks: @@ -28,35 +28,43 @@ services: - ./data/consul/consul1/config:/consul/config consul2: - image: consul:latest + image: consul:1.13.9 container_name: consul2 restart: always networks: - shenyu + depends_on: + - consul1 command: agent -server -client=0.0.0.0 -bind 0.0.0.0 -retry-join=consul1 -node=consul2 volumes: - ./data/consul/consul2/data:/consul/data - ./data/consul/consul2/config:/consul/config consul3: - image: consul:latest + image: consul:1.13.9 container_name: consul3 restart: always networks: - shenyu + depends_on: + - consul1 command: agent -server -client=0.0.0.0 -bind 0.0.0.0 -retry-join=consul1 -node=consul3 volumes: - ./data/consul/consul3/data:/consul/data - ./data/consul/consul3/config:/consul/config consul4: - image: consul:latest + image: consul:1.13.9 container_name: consul4 restart: always ports: - 8500:8500 networks: - shenyu + depends_on: + - consul1 + - consul2 + - consul3 command: agent -client=0.0.0.0 -bind 0.0.0.0 -retry-join=consul1 -ui -node=client1 volumes: - ./data/consul/consul4/data:/consul/data diff --git a/example/http_client/http_client.go b/example/http_client/http_client.go index 696c786..fb91dde 100644 --- a/example/http_client/http_client.go +++ b/example/http_client/http_client.go @@ -37,7 +37,7 @@ func main() { adminToken, err := clients.NewShenYuAdminClient(adminClient) if err == nil { - fmt.Printf("this is ShenYu Admin client token %v ->", adminToken.AdminTokenData.Token) + fmt.Printf("this is ShenYu Admin client token: %v\n", adminToken.AdminTokenData.Token) } //init MetaDataRegister @@ -48,12 +48,13 @@ func main() { Enabled: true, //require user provide Host: "127.0.0.1", //require user provide Port: "8080", //require user provide + NamespaceId: "public", //require user provide } result, err := clients.RegisterMetaData(adminToken.AdminTokenData, metaData) if err != nil { - fmt.Printf("MetaDataRegister has error %v:", err) + fmt.Printf("MetaDataRegister has error: %v\n", err) } - fmt.Printf("finish register metadata ,the result is %v ->", result) + fmt.Printf("finish register metadata ,the result is: %v\n", result) //init urlRegister urlRegister := &model.URIRegister{ @@ -63,12 +64,13 @@ func main() { RPCType: constants.RPCTYPE_HTTP, //require user provide Host: "127.0.0.1", //require user provide Port: "8080", //require user provide + NamespaceId: "public", //require user provide } result, err = clients.UrlRegister(adminToken.AdminTokenData, urlRegister) if err != nil { - fmt.Printf("UrlRegister has error %v:", err) + fmt.Printf("UrlRegister has error: %v\n", err) } - fmt.Printf("finish UrlRegister ,the result is %v ->", result) + fmt.Printf("finish UrlRegister ,the result is: %v\n", result) //do you logic } diff --git a/example/nacos_client/nacos_client.go b/example/nacos_client/nacos_client.go index fd94179..d98f06b 100644 --- a/example/nacos_client/nacos_client.go +++ b/example/nacos_client/nacos_client.go @@ -39,7 +39,7 @@ func main() { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) diff --git a/example/nacos_client/nacos_client_test.go b/example/nacos_client/nacos_client_test.go index 8ac2c9a..17ab876 100644 --- a/example/nacos_client/nacos_client_test.go +++ b/example/nacos_client/nacos_client_test.go @@ -38,7 +38,7 @@ func TestInitNacosClient(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -57,7 +57,7 @@ func TestInitNacosClientAndRegister(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -107,7 +107,7 @@ func TestRegisterAndGetInstance(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) @@ -171,7 +171,7 @@ func TestRegisterAndDeregister(t *testing.T) { ncp := &nacos_client.NacosClientParam{ IpAddr: "console.nacos.io", Port: 80, - NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468", + NamespaceId: "public", } sdkClient := shenyu_sdk_client.GetFactoryClient(constants.NACOS_CLIENT) diff --git a/example/zk_client/zk_client_test.go b/example/zk_client/zk_client_test.go index 4dbcfb9..c984934 100644 --- a/example/zk_client/zk_client_test.go +++ b/example/zk_client/zk_client_test.go @@ -116,6 +116,20 @@ func TestRegisterServiceInstanceAndGetServiceInstanceInfo(t *testing.T) { instanceDetail3, err := zc.GetServiceInstanceInfo(metaData3) assert.NotNil(t, instanceDetail3) assert.Nil(t, err) + + time.Sleep(time.Second) + + deRegisterResult1, err := zc.DeregisterServiceInstance(metaData1) + assert.Nil(t, err) + assert.True(t, deRegisterResult1) + + deRegisterResult2, err := zc.DeregisterServiceInstance(metaData2) + assert.Nil(t, err) + assert.True(t, deRegisterResult2) + + deRegisterResult3, err := zc.DeregisterServiceInstance(metaData3) + assert.Nil(t, err) + assert.True(t, deRegisterResult3) } /** diff --git a/model/common_meta_data_register.go b/model/common_meta_data_register.go index 8721e7d..cbf65ad 100644 --- a/model/common_meta_data_register.go +++ b/model/common_meta_data_register.go @@ -32,4 +32,5 @@ type MetaDataRegister struct { PluginNames []interface{} `json:"pluginNames"` RegisterMetaData bool `json:"registerMetaData"` TimeMillis int64 `json:"timeMillis"` + NamespaceId string `json:"namespaceId"` } diff --git a/model/http_url_register.go b/model/http_url_register.go index 712fe95..b638062 100644 --- a/model/http_url_register.go +++ b/model/http_url_register.go @@ -27,4 +27,5 @@ type URIRegister struct { RPCType string `json:"rpcType"` Host string `json:"host"` Port string `json:"port"` + NamespaceId string `json:"namespaceId"` }