Skip to content

Commit

Permalink
[Feature: Supports nacos2.x.]
Browse files Browse the repository at this point in the history
  • Loading branch information
koonchen committed Dec 1, 2024
1 parent f6181c6 commit 8488caa
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 107 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.18

- name: Check out code
uses: actions/checkout@v1
Expand All @@ -40,7 +40,7 @@ jobs:
name: Test
strategy:
matrix:
go-version: [ 1.14.x, 1.15.x, 1.16.x ]
go-version: [ 1.18.x, 1.19.x ]
runs-on: ubuntu-latest
steps:
- name: Set up Go
Expand All @@ -51,10 +51,18 @@ jobs:
- name: Check out code
uses: actions/checkout@v1

- name: Install docker-compose
- name: Install docker-compose & nacos-init-sql
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
sudo mkdir -p initdb.d
sudo curl -o initdb.d/mysql-schema.sql https://raw.githubusercontent.com/alibaba/nacos/master/distribution/conf/mysql-schema.sql
- name: Create Docker network
run: docker network create -d bridge shenyu

- name: Start Nacos Docker Compose
run: docker-compose -f docker-compose-nacos.yml up -d

- name: Start Zookeeper Docker Compose
run: docker-compose -f docker-compose-zk.yml up -d
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.13.x
go-version: 1.18.x

- name: Check out code
uses: actions/checkout@v3
Expand All @@ -37,4 +37,4 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout 5m
args: --timeout 5m --out-format colored-line-number
8 changes: 4 additions & 4 deletions clients/nacos_client/nacos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package nacos_client

import (
oriNc "github.com/nacos-group/nacos-sdk-go/clients"
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/common/constant"
"github.com/nacos-group/nacos-sdk-go/vo"
oriNc "github.com/nacos-group/nacos-sdk-go/v2/clients"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/v2/common/constant"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"github.com/sirupsen/logrus"
)

Expand Down
4 changes: 2 additions & 2 deletions doc/NACOS_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
```go
//设置nacos环境配置
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1",
Port: 8848,
NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468",
}
```
Expand Down
4 changes: 2 additions & 2 deletions doc/NACOS_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
```go
//set nacos env configuration
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1,
Port: 8848,
NamespaceId: "e525eafa-f7d7-4029-83d9-008937f9d468",
}
```
Expand Down
1 change: 1 addition & 0 deletions docker-compose-consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ services:
networks:
shenyu:
name: shenyu
external: true
1 change: 1 addition & 0 deletions docker-compose-etcd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ services:
networks:
shenyu:
name: shenyu
external: true
62 changes: 62 additions & 0 deletions docker-compose-nacos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# 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.
version: "3.1"

services:
mysql:
image: mysql:8.0
container_name: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: nacos_dev
volumes:
- ./initdb.d:/docker-entrypoint-initdb.d
networks:
- shenyu
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
interval: 5s
timeout: 10s
retries: 10
shenyu-nacos:
image: nacos/nacos-server:v2.2.3
container_name: shenyu-nacos
environment:
MODE: standalone
PREFER_HOST_MODE: hostname
SPRING_DATASOURCE_PLATFORM: mysql
MYSQL_SERVICE_HOST: mysql
MYSQL_SERVICE_PORT: 3306
MYSQL_SERVICE_USER: root
MYSQL_SERVICE_PASSWORD: 123456
MYSQL_SERVICE_DB_NAME: nacos_dev
MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
ports:
- "8848:8848"
- "9848:9848"
- "9849:9849"
depends_on:
mysql:
condition: service_healthy
networks:
- shenyu

networks:
shenyu:
name: shenyu
external: true
25 changes: 13 additions & 12 deletions docker-compose-zk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,46 @@
version: "3.1"

services:
shenyu1:
zk1:
container_name: shenyu-zk1
image: zookeeper
image: zookeeper:latest
restart: always
hostname: shenyu1
hostname: zk1
ports:
- 2181:2181
networks:
- shenyu
environment:
ZOO_MY_ID: 1
ZOO_SERVERS: server.1=shenyu1:2888:3888;2181 server.2=shenyu2:2888:3888;2181 server.3=shenyu3:2888:3888;2181
ZOO_SERVERS: server.1=zk1:2888:3888;2181 server.2=zk2:2888:3888;2181 server.3=zk3:2888:3888;2181

shenyu2:
zk2:
container_name: shenyu-zk2
image: zookeeper
image: zookeeper:latest
restart: always
hostname: shenyu2
hostname: zk2
ports:
- 2182:2181
networks:
- shenyu
environment:
ZOO_MY_ID: 2
ZOO_SERVERS: server.1=shenyu1:2888:3888;2181 server.2=shenyu2:2888:3888;2181 server.3=shenyu3:2888:3888;2181
ZOO_SERVERS: server.1=zk1:2888:3888;2181 server.2=zk2:2888:3888;2181 server.3=zk3:2888:3888;2181

shenyu3:
zk3:
container_name: shenyu-zk3
image: zookeeper
image: zookeeper:latest
restart: always
hostname: shenyu3
hostname: zk3
ports:
- 2183:2181
networks:
- shenyu
environment:
ZOO_MY_ID: 3
ZOO_SERVERS: server.1=shenyu1:2888:3888;2181 server.2=shenyu2:2888:3888;2181 server.3=shenyu3:2888:3888;2181
ZOO_SERVERS: server.1=zk1:2888:3888;2181 server.2=zk2:2888:3888;2181 server.3=zk3:2888:3888;2181

networks:
shenyu:
name: shenyu
external: true
8 changes: 4 additions & 4 deletions example/nacos_client/nacos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/apache/shenyu-client-golang/common/constants"
"github.com/apache/shenyu-client-golang/common/shenyu_sdk_client"
"github.com/apache/shenyu-client-golang/model"
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"time"
)

Expand All @@ -37,8 +37,8 @@ func main() {
//Create ShenYuNacosClient start
//set nacos env configuration
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1",
Port: 8848,
NamespaceId: "public",
}

Expand Down
22 changes: 12 additions & 10 deletions example/nacos_client/nacos_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/apache/shenyu-client-golang/common/constants"
"github.com/apache/shenyu-client-golang/common/shenyu_sdk_client"
"github.com/apache/shenyu-client-golang/model"
"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/vo"
"github.com/nacos-group/nacos-sdk-go/v2/clients/naming_client"
"github.com/nacos-group/nacos-sdk-go/v2/vo"
"github.com/stretchr/testify/assert"
"testing"
"time"
Expand All @@ -36,8 +36,8 @@ import (
func TestInitNacosClient(t *testing.T) {
//set nacos env configuration
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1",
Port: 8848,
NamespaceId: "public",
}

Expand All @@ -55,8 +55,8 @@ func TestInitNacosClient(t *testing.T) {
func TestInitNacosClientAndRegister(t *testing.T) {
//set nacos env configuration
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1",
Port: 8848,
NamespaceId: "public",
}

Expand Down Expand Up @@ -93,6 +93,8 @@ func TestInitNacosClientAndRegister(t *testing.T) {
Healthy: true, //require user provide
Ephemeral: true, //require user provide
Metadata: map[string]string{"contextPath": "contextPath", "uriMetadata": string(metaDataStringJson)},
ClusterName: "DEFAULT",
GroupName: "DEFAULT_GROUP",
}

instance, err := nc.RegisterServiceInstance(nacosRegisterInstance)
Expand All @@ -106,8 +108,8 @@ func TestInitNacosClientAndRegister(t *testing.T) {
func TestRegisterAndGetInstance(t *testing.T) {
//set nacos env configuration
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1",
Port: 8848,
NamespaceId: "public",
}

Expand Down Expand Up @@ -171,8 +173,8 @@ func TestRegisterAndGetInstance(t *testing.T) {
func TestRegisterAndDeregister(t *testing.T) {
//set nacos env configuration
ncp := &nacos_client.NacosClientParam{
IpAddr: "console.nacos.io",
Port: 80,
IpAddr: "127.0.0.1",
Port: 8848,
NamespaceId: "public",
}

Expand Down
Loading

0 comments on commit 8488caa

Please sign in to comment.