Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ftr: consul registry #121

Merged
merged 54 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d04c33e
consul init
Jun 21, 2019
858f7c9
update
Jun 21, 2019
26959d1
solve conflict
Jul 1, 2019
dc0e93b
update consul
Jul 2, 2019
a231f0e
add consul example
Jul 2, 2019
5e0a4a1
Merge branch 'master' into consul
Jul 3, 2019
7564165
go mod
Jul 3, 2019
0adb3a9
go fmt
Jul 3, 2019
dcde19b
fix bug: add wg.done
Jul 3, 2019
127f034
Merge branch 'master' into consul
Jul 3, 2019
461cfc3
Merge branch 'develop' into consul
Jul 3, 2019
8970b13
modify travis
Jul 3, 2019
218cc74
new go.sum
Jul 3, 2019
c37e13a
modify go mod
Jul 3, 2019
65ae799
new go.mod and go.sum
Jul 4, 2019
eeb1177
update gitignore
Jul 4, 2019
f82563f
merge develop branch
Jul 9, 2019
87e9bab
modify based rw
Jul 9, 2019
340b98b
fix bug
Jul 9, 2019
85582d5
add for
Jul 9, 2019
cbb0534
improve consul examples
Jul 12, 2019
64df877
merge develop
Jul 17, 2019
97e0e51
add consul in travis
Jul 17, 2019
01485b5
modify travis
Jul 17, 2019
c8e0403
modify travis
Jul 17, 2019
f671f55
modify travis
Jul 17, 2019
bc10a18
modify travis
Jul 17, 2019
1ca3536
modfiy travis
Jul 17, 2019
4b29e7c
modify travis
Jul 17, 2019
e4a39c9
add unit test for consul
Jul 27, 2019
588dd96
resolve conflict
Jul 27, 2019
1bb5457
fix typo
Jul 31, 2019
82fb516
recolve conflict
Aug 11, 2019
a958f13
resolve conflict
Aug 11, 2019
f616b4a
fix initialize len and cap for make
Aug 11, 2019
803c1b2
resolve conflict
Aug 14, 2019
24e7d6f
Merge branch 'develop' into consul
Aug 14, 2019
1edd0f5
Merge branch 'develop' into consul
Aug 19, 2019
bd25bbd
fix typo
Aug 19, 2019
114b0c9
Merge branch 'develop' into consul
Aug 19, 2019
38a4b0c
consul test
Aug 19, 2019
2aa483a
consul test
Aug 19, 2019
46cc00a
travis
Aug 19, 2019
11032c5
import
Aug 19, 2019
5c05d1c
fix typo
Aug 19, 2019
c52c611
Merge branch 'develop' into consul
Aug 19, 2019
dd8728e
test
Aug 19, 2019
85c89b7
revert
Aug 19, 2019
e77abb3
go mod
Aug 20, 2019
d11fff0
typo
Aug 20, 2019
8125771
modify version
Aug 22, 2019
f73ee62
examples
Aug 22, 2019
21d7b15
add unregister test
Aug 23, 2019
5dd2bd0
modify yaml
Aug 23, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ coverage.txt
target/
classes


# Gopkg.lock
# go mod, go test
vendor/
coverage.txt

logs/
.vscode/
Expand Down
4 changes: 4 additions & 0 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ func WithParams(params url.Values) option {
url.Params = params
}
}

func WithParamsValue(key, val string) option {
return func(url *URL) {
url.Params.Set(key, val)
}
}

func WithProtocol(proto string) option {
return func(url *URL) {
url.Protocol = proto
}
}

func WithIp(ip string) option {
return func(url *URL) {
url.Ip = ip
Expand All @@ -141,6 +144,7 @@ func WithLocation(location string) option {
url.Location = location
}
}

func NewURLWithOptions(opts ...option) *URL {
url := &URL{}
for _, opt := range opts {
Expand Down
11 changes: 5 additions & 6 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ var (
maxWait = 3
)

// loaded comsumer & provider config from xxx.yml, and log config from xxx.xml
// Namely: dubbo.comsumer.xml & dubbo.provider.xml in java dubbo
// loaded consumer & provider config from xxx.yml, and log config from xxx.xml
// Namely: dubbo.consumer.xml & dubbo.provider.xml in java dubbo
func init() {
var (
confConFile, confProFile string
Expand Down Expand Up @@ -70,9 +70,8 @@ func Load() {
SetConsumerService(genericService)
}
rpcService := GetConsumerService(key)

if rpcService == nil {
logger.Warnf("%s is not exsist!", key)
logger.Warnf("%s does not exist!", key)
continue
}
ref.id = key
Expand All @@ -99,7 +98,7 @@ func Load() {
break
}
if refconfig.invoker == nil {
logger.Warnf("The interface %s invoker not exsist , may you should check your interface config.", refconfig.InterfaceName)
logger.Warnf("The interface %s invoker not exist , may you should check your interface config.", refconfig.InterfaceName)
}
}
}
Expand All @@ -120,7 +119,7 @@ func Load() {
for key, svs := range providerConfig.Services {
rpcService := GetProviderService(key)
if rpcService == nil {
logger.Warnf("%s is not exsist!", key)
logger.Warnf("%s does not exist!", key)
continue
}
svs.id = key
Expand Down
44 changes: 44 additions & 0 deletions examples/consul/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# consul
gaoxinge marked this conversation as resolved.
Show resolved Hide resolved

Examples for consul registry. Before running examples below, make sure that consul has been started.

## requirement

- consul
- go 1.12
- java 8
- maven 3.6.1

## go-server

```
$ cd examples/consul/go-server
$ export CONF_PROVIDER_FILE_PATH="config/server.yml"
$ export APP_LOG_CONF_FILE="config/log.yml"
$ go run .
```

## go-client

```
$ cd examples/consul/go-client
$ export CONF_CONSUMER_FILE_PATH="config/client.yml"
$ export APP_LOG_CONF_FILE="config/log.yml"
$ go run .
```

## java-server

```
$ cd examples/consul/java-server
$ mvn clean package
$ java -jar target/java-server-1.0.0.jar
```

## java-client

```
$ cd examples/consul/java-client
$ mvn clean package
$ java -jar target/java-client-1.0.0.jar
```
43 changes: 43 additions & 0 deletions examples/consul/go-client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 (
"fmt"
)

import (
_ "github.com/apache/dubbo-go/cluster/cluster_impl"
_ "github.com/apache/dubbo-go/cluster/loadbalance"
_ "github.com/apache/dubbo-go/common/proxy/proxy_factory"
"github.com/apache/dubbo-go/config"
_ "github.com/apache/dubbo-go/filter/impl"
_ "github.com/apache/dubbo-go/protocol/dubbo"
_ "github.com/apache/dubbo-go/registry/consul"
_ "github.com/apache/dubbo-go/registry/protocol"
)

func main() {
config.Load()

message, err := dubboService.SayHello([]interface{}{"world"})
if err != nil {
panic(err)
}
fmt.Println(message)
}
58 changes: 58 additions & 0 deletions examples/consul/go-client/config/client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# dubbo client yaml configure file


check: true
# client
request_timeout : "3s"
# connect timeout
connect_timeout : "3s"

# application config
application_config:
organization : "ikurento.com"
name : "BDTService"
module : "dubbogo user-info client"
version : "0.0.1"
owner : "ZX"
environment : "test"

registries :
"hangzhouzk":
protocol: "consul"
timeout : "3s"
address: "127.0.0.1:8500"
username: ""
password: ""

references:
"DubboService":
protocol : "dubbo"
interface : "dubbo.DubboService"
cluster: "failover"
methods :
- name: "SayHello"
retries: 3

protocol_conf:
dubbo:
reconnect_interval: 0
connection_number: 2
heartbeat_period: "5s"
session_timeout: "20s"
fail_fast_timeout: "5s"
pool_size: 64
pool_ttl: 600
getty_session_param:
compress_encoding: false
tcp_no_delay: true
tcp_keep_alive: true
keep_alive_period: "120s"
tcp_r_buf_size: 262144
tcp_w_buf_size: 65536
pkg_rq_size: 1024
pkg_wq_size: 512
tcp_read_timeout: "1s"
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 10240
session_name: "client"
28 changes: 28 additions & 0 deletions examples/consul/go-client/config/log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

level: "info"
development: false
disableCaller: false
disableStacktrace: true
sampling:
encoding: "console"

# encoder
encoderConfig:
messageKey: "message"
levelKey: "level"
timeKey: "time"
nameKey: "logger"
callerKey: "caller"
stacktraceKey: "stacktrace"
lineEnding: ""
levelEncoder: "capitalColor"
timeEncoder: "iso8601"
durationEncoder: "seconds"
callerEncoder: "short"
nameEncoder: ""

outputPaths:
- "stderr"
errorOutputPaths:
- "stderr"
initialFields:
36 changes: 36 additions & 0 deletions examples/consul/go-client/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 (
"github.com/apache/dubbo-go/config"
)

var dubboService = new(DubboService)

func init() {
config.SetConsumerService(dubboService)
}

type DubboService struct {
SayHello func(req interface{}) (string, error)
}

func (s *DubboService) Reference() string {
return "DubboService"
}
28 changes: 28 additions & 0 deletions examples/consul/go-server/config/log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

level: "info"
development: false
disableCaller: false
disableStacktrace: true
sampling:
encoding: "console"

# encoder
encoderConfig:
messageKey: "message"
levelKey: "level"
timeKey: "time"
nameKey: "logger"
callerKey: "caller"
stacktraceKey: "stacktrace"
lineEnding: ""
levelEncoder: "capitalColor"
timeEncoder: "iso8601"
durationEncoder: "seconds"
callerEncoder: "short"
nameEncoder: ""

outputPaths:
- "stderr"
errorOutputPaths:
- "stderr"
initialFields:
58 changes: 58 additions & 0 deletions examples/consul/go-server/config/server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# dubbo server yaml configure file


# application config
application_config:
organization : "ikurento.com"
name : "BDTService"
module : "dubbogo user-info server"
version : "0.0.1"
owner : "ZX"
environment : "test"

registries :
"hangzhouzk":
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
protocol: "consul"
timeout : "3s"
address: "127.0.0.1:8500"
username: ""
password: ""

services:
"DubboService":
protocol : "dubbo"
interface : "dubbo.DubboService"
loadbalance: "random"
warmup: "100"
cluster: "failover"
methods:
- name: "SayHello"
retries: 1
loadbalance: "random"

protocols:
"dubbo1":
name: "dubbo"
# ip : "127.0.0.1"
port: 20000


protocol_conf:
dubbo:
session_number: 700
fail_fast_timeout: "5s"
session_timeout: "20s"
getty_session_param:
compress_encoding: false
tcp_no_delay: true
tcp_keep_alive: true
keep_alive_period: "120s"
tcp_r_buf_size: 262144
tcp_w_buf_size: 65536
pkg_rq_size: 1024
pkg_wq_size: 512
tcp_read_timeout: "1s"
tcp_write_timeout: "5s"
wait_timeout: "1s"
max_msg_len: 1024
session_name: "server"
Loading