diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000000000000000000000000000000000000..a9bd809c5c43a9d88a773b5f0c421b252abf38de --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +Apache Dubbo Go +Copyright 2018-2019 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). diff --git a/README.md b/README.md index 593be70222b69f5aa62ac0b781a0a3be6b0e1ff5..ccc6ae52edf5f5086213feb3d3d0823ed46e0b96 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ --- Apache Dubbo Go Implementation. + + +Apache/Dubbo-go image, licensed under [Creative Commons 3.0 Attributions license](https://creativecommons.org/licenses/by/3.0/). + ## License Apache License, Version 2.0 @@ -29,7 +33,7 @@ Finished List: - Role: Consumer, Provider - Transport: HTTP, TCP - Codec: JsonRPC v2, Hessian v2 -- Registry: ZooKeeper +- Registry: ZooKeeper/[etcd](https://github.com/apache/dubbo-go/pull/148)/[nacos](https://github.com/apache/dubbo-go/pull/151) - Configure Center: Zookeeper - Cluster Strategy: Failover/[Failfast](https://github.com/apache/dubbo-go/pull/140)/[Failsafe/Failback](https://github.com/apache/dubbo-go/pull/136)/Available/Broadcast - Load Balance: Random/[RoundRobin](https://github.com/apache/dubbo-go/pull/66)/[LeastActive](https://github.com/apache/dubbo-go/pull/65) @@ -41,7 +45,7 @@ Working List: - Cluster Strategy: Forking - Load Balance: ConsistentHash - Filter: TokenFilter/AccessLogFilter/CountFilter/ExecuteLimitFilter/TpsLimitFilter -- Registry: etcd/k8s/consul/nacos +- Registry: k8s/consul - Configure Center: apollo - Dynamic Configuration Center & Metadata Center (dubbo v2.7.x) - Metrics: Promethus(dubbo v2.7.x) diff --git a/README_CN.md b/README_CN.md index 7732a655adfbaa2a2a963201d6580767758c4fce..e021be55765241be93f4c9c66cca1beb573cc1bb 100644 --- a/README_CN.md +++ b/README_CN.md @@ -5,6 +5,9 @@ --- Apache Dubbo Go 璇█瀹炵幇 + + +Apache/Dubbo-go image, licensed under [Creative Commons 3.0 Attributions license](https://creativecommons.org/licenses/by/3.0/). ## 璇佷功 ## @@ -29,7 +32,7 @@ Apache License, Version 2.0 - 瑙掕壊绔�: Consumer, Provider - 浼犺緭鍗忚: HTTP, TCP - 搴忓垪鍖栧崗璁�: JsonRPC v2, Hessian v2 -- 娉ㄥ唽涓績: ZooKeeper +- 娉ㄥ唽涓績: ZooKeeper/[etcd](https://github.com/apache/dubbo-go/pull/148)/[nacos](https://github.com/apache/dubbo-go/pull/151) - 閰嶇疆涓績: Zookeeper - 闆嗙兢绛栫暐: Failover/[Failfast](https://github.com/apache/dubbo-go/pull/140)/[Failsafe/Failback](https://github.com/apache/dubbo-go/pull/136)/Available/Broadcast - 璐熻浇鍧囪 绛栫暐: Random/[RoundRobin](https://github.com/apache/dubbo-go/pull/66)/[LeastActive](https://github.com/apache/dubbo-go/pull/65) diff --git a/cluster/cluster_impl/forking_cluster.go b/cluster/cluster_impl/forking_cluster.go new file mode 100644 index 0000000000000000000000000000000000000000..0a3c2b313ff3c4e89e592af9256fc42713419914 --- /dev/null +++ b/cluster/cluster_impl/forking_cluster.go @@ -0,0 +1,40 @@ +/* +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 cluster_impl + +import ( + "github.com/apache/dubbo-go/cluster" + "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/protocol" +) + +type forkingCluster struct{} + +const forking = "forking" + +func init() { + extension.SetCluster(forking, NewForkingCluster) +} + +func NewForkingCluster() cluster.Cluster { + return &forkingCluster{} +} + +func (cluster *forkingCluster) Join(directory cluster.Directory) protocol.Invoker { + return newForkingClusterInvoker(directory) +} diff --git a/cluster/cluster_impl/forking_cluster_invoker.go b/cluster/cluster_impl/forking_cluster_invoker.go new file mode 100644 index 0000000000000000000000000000000000000000..d6cf2f4b89ab4f322fa758deecae90c60742ef49 --- /dev/null +++ b/cluster/cluster_impl/forking_cluster_invoker.go @@ -0,0 +1,99 @@ +/* +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 cluster_impl + +import ( + "errors" + "fmt" + "time" +) + +import ( + "github.com/Workiva/go-datastructures/queue" +) + +import ( + "github.com/apache/dubbo-go/cluster" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/logger" + "github.com/apache/dubbo-go/protocol" +) + +type forkingClusterInvoker struct { + baseClusterInvoker +} + +func newForkingClusterInvoker(directory cluster.Directory) protocol.Invoker { + return &forkingClusterInvoker{ + baseClusterInvoker: newBaseClusterInvoker(directory), + } +} + +func (invoker *forkingClusterInvoker) Invoke(invocation protocol.Invocation) protocol.Result { + err := invoker.checkWhetherDestroyed() + if err != nil { + return &protocol.RPCResult{Err: err} + } + + invokers := invoker.directory.List(invocation) + err = invoker.checkInvokers(invokers, invocation) + if err != nil { + return &protocol.RPCResult{Err: err} + } + + var selected []protocol.Invoker + forks := int(invoker.GetUrl().GetParamInt(constant.FORKS_KEY, constant.DEFAULT_FORKS)) + timeouts := invoker.GetUrl().GetParamInt(constant.TIMEOUT_KEY, constant.DEFAULT_TIMEOUT) + if forks < 0 || forks > len(invokers) { + selected = invokers + } else { + selected = make([]protocol.Invoker, 0) + loadbalance := getLoadBalance(invokers[0], invocation) + for i := 0; i < forks; i++ { + ivk := invoker.doSelect(loadbalance, invocation, invokers, selected) + if ivk != nil { + selected = append(selected, ivk) + } + } + } + + resultQ := queue.New(1) + for _, ivk := range selected { + go func(k protocol.Invoker) { + result := k.Invoke(invocation) + err := resultQ.Put(result) + if err != nil { + logger.Errorf("resultQ put failed with exception: %v.\n", err) + } + }(ivk) + } + + rsps, err := resultQ.Poll(1, time.Millisecond*time.Duration(timeouts)) + if err != nil { + return &protocol.RPCResult{ + Err: errors.New(fmt.Sprintf("failed to forking invoke provider %v, but no luck to perform the invocation. Last error is: %s", selected, err.Error()))} + } + if len(rsps) == 0 { + return &protocol.RPCResult{Err: errors.New(fmt.Sprintf("failed to forking invoke provider %v, but no resp", selected))} + } + result, ok := rsps[0].(protocol.Result) + if !ok { + return &protocol.RPCResult{Err: errors.New(fmt.Sprintf("failed to forking invoke provider %v, but not legal resp", selected))} + } + return result +} diff --git a/cluster/cluster_impl/forking_cluster_test.go b/cluster/cluster_impl/forking_cluster_test.go new file mode 100644 index 0000000000000000000000000000000000000000..8603f8aedc4e28a3a4ca2f115355debc1a5ecc62 --- /dev/null +++ b/cluster/cluster_impl/forking_cluster_test.go @@ -0,0 +1,162 @@ +/* +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 cluster_impl + +import ( + "context" + "strconv" + "sync" + "testing" + "time" +) + +import ( + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" +) + +import ( + "github.com/apache/dubbo-go/cluster/directory" + "github.com/apache/dubbo-go/cluster/loadbalance" + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/protocol" + "github.com/apache/dubbo-go/protocol/invocation" + "github.com/apache/dubbo-go/protocol/mock" +) + +var ( + forkingUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider") +) + +func registerForking(t *testing.T, mockInvokers ...*mock.MockInvoker) protocol.Invoker { + extension.SetLoadbalance(loadbalance.RoundRobin, loadbalance.NewRoundRobinLoadBalance) + + invokers := []protocol.Invoker{} + for i, ivk := range mockInvokers { + invokers = append(invokers, ivk) + if i == 0 { + ivk.EXPECT().GetUrl().Return(forkingUrl) + } + } + staticDir := directory.NewStaticDirectory(invokers) + + forkingCluster := NewForkingCluster() + clusterInvoker := forkingCluster.Join(staticDir) + return clusterInvoker +} + +func Test_ForkingInvokeSuccess(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + invokers := make([]*mock.MockInvoker, 0) + + mockResult := &protocol.RPCResult{Rest: rest{tried: 0, success: true}} + forkingUrl.AddParam(constant.FORKS_KEY, strconv.Itoa(3)) + //forkingUrl.AddParam(constant.TIMEOUT_KEY, strconv.Itoa(constant.DEFAULT_TIMEOUT)) + + var wg sync.WaitGroup + wg.Add(2) + for i := 0; i < 2; i++ { + invoker := mock.NewMockInvoker(ctrl) + invokers = append(invokers, invoker) + invoker.EXPECT().IsAvailable().Return(true).AnyTimes() + invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn( + func(invocation protocol.Invocation) protocol.Result { + wg.Done() + return mockResult + }) + } + + clusterInvoker := registerForking(t, invokers...) + + result := clusterInvoker.Invoke(&invocation.RPCInvocation{}) + assert.Equal(t, mockResult, result) + wg.Wait() +} + +func Test_ForkingInvokeTimeout(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + invokers := make([]*mock.MockInvoker, 0) + + mockResult := &protocol.RPCResult{Rest: rest{tried: 0, success: true}} + forkingUrl.AddParam(constant.FORKS_KEY, strconv.Itoa(3)) + + var wg sync.WaitGroup + wg.Add(2) + for i := 0; i < 2; i++ { + invoker := mock.NewMockInvoker(ctrl) + invokers = append(invokers, invoker) + invoker.EXPECT().IsAvailable().Return(true).AnyTimes() + invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn( + func(invocation protocol.Invocation) protocol.Result { + time.Sleep(2 * time.Second) + wg.Done() + return mockResult + }) + } + + clusterInvoker := registerForking(t, invokers...) + + result := clusterInvoker.Invoke(&invocation.RPCInvocation{}) + assert.NotNil(t, result) + assert.NotNil(t, result.Error()) + wg.Wait() +} + +func Test_ForkingInvokeHalfTimeout(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + invokers := make([]*mock.MockInvoker, 0) + + mockResult := &protocol.RPCResult{Rest: rest{tried: 0, success: true}} + forkingUrl.AddParam(constant.FORKS_KEY, strconv.Itoa(3)) + + var wg sync.WaitGroup + wg.Add(2) + for i := 0; i < 2; i++ { + invoker := mock.NewMockInvoker(ctrl) + invokers = append(invokers, invoker) + invoker.EXPECT().IsAvailable().Return(true).AnyTimes() + if i == 1 { + invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn( + func(invocation protocol.Invocation) protocol.Result { + wg.Done() + return mockResult + }) + } else { + invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn( + func(invocation protocol.Invocation) protocol.Result { + time.Sleep(2 * time.Second) + wg.Done() + return mockResult + }) + } + } + + clusterInvoker := registerForking(t, invokers...) + + result := clusterInvoker.Invoke(&invocation.RPCInvocation{}) + assert.Equal(t, mockResult, result) + wg.Wait() +} diff --git a/common/constant/key.go b/common/constant/key.go index 3441b341d038e505e8e1f4444adb4cecc2d8b847..ed60c24b633fa62bbdf5b45931b286c6bbcd932b 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -48,6 +48,9 @@ const ( RETRIES_KEY = "retries" BEAN_NAME = "bean.name" FAIL_BACK_TASKS_KEY = "failbacktasks" + FORKS_KEY = "forks" + DEFAULT_FORKS = 2 + DEFAULT_TIMEOUT = 1000 ) const ( diff --git a/config/reference_config_test.go b/config/reference_config_test.go index 296cde65fad6017b930ef06e0045a45b4af27c86..774fece29f5158b6840b3384b5c56846cc4da37b 100644 --- a/config/reference_config_test.go +++ b/config/reference_config_test.go @@ -20,6 +20,8 @@ package config import ( "sync" "testing" + + "github.com/apache/dubbo-go/common/constant" ) import ( @@ -82,6 +84,7 @@ func doInit() { "MockService": { Params: map[string]string{ "serviceid": "soa.mock", + "forks": "5", }, Registry: "shanghai_reg1,shanghai_reg2,hangzhou_reg1,hangzhou_reg2", InterfaceName: "com.MockService", @@ -190,6 +193,23 @@ func Test_Implement(t *testing.T) { consumerConfig = nil } +func Test_Forking(t *testing.T) { + doInit() + extension.SetProtocol("dubbo", GetProtocol) + extension.SetProtocol("registry", GetProtocol) + m := consumerConfig.References["MockService"] + m.Url = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000" + + for _, reference := range consumerConfig.References { + reference.Refer() + forks := int(reference.invoker.GetUrl().GetParamInt(constant.FORKS_KEY, constant.DEFAULT_FORKS)) + assert.Equal(t, 5, forks) + assert.NotNil(t, reference.pxy) + assert.NotNil(t, reference.Cluster) + } + consumerConfig = nil +} + func GetProtocol() protocol.Protocol { if regProtocol != nil { return regProtocol diff --git a/config/testdata/consumer_config.yml b/config/testdata/consumer_config.yml index 373871dccbc6c3f7272b7abcb1a9a104c8f13090..372873abbb258e03acfe8e9e00d03aa2f77fb9a9 100644 --- a/config/testdata/consumer_config.yml +++ b/config/testdata/consumer_config.yml @@ -47,6 +47,7 @@ references: params: "serviceid": "soa.com.ikurento.user.UserProvider" + "forks": 5 protocol_conf: dubbo: diff --git a/dubbogo.png b/dubbogo.png new file mode 100644 index 0000000000000000000000000000000000000000..2cac434091276df102c3ae405c09621b8d8926ef Binary files /dev/null and b/dubbogo.png differ diff --git a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go index 5da8506d5d0a3f16388446fe29799ffb28023c7f..d27af7a31778403d518e6454de7ebab4b9b5cdf7 100644 --- a/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go +++ b/examples/configcenter/zookeeper/dubbo/with-configcenter-go-client/app/client.go @@ -140,7 +140,7 @@ func initSignal() { os.Exit(1) }) - // The program exits normally or timeout forcibly exits.// + // The program exits normally or timeout forcibly exits. fmt.Println("app exit now...") return } diff --git a/examples/general/dubbo/go-client/app/client.go b/examples/general/dubbo/go-client/app/client.go index 47f453c3a451a4c6d98f40e1ec7e7618440fe4f9..e839b0b2776d8e3b2aba2756d2a622bea2b8e88d 100644 --- a/examples/general/dubbo/go-client/app/client.go +++ b/examples/general/dubbo/go-client/app/client.go @@ -33,7 +33,6 @@ import ( "github.com/apache/dubbo-go/common/logger" _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" "github.com/apache/dubbo-go/config" - "github.com/apache/dubbo-go/protocol/dubbo" _ "github.com/apache/dubbo-go/registry/protocol" _ "github.com/apache/dubbo-go/filter/impl" @@ -64,8 +63,6 @@ func main() { test1() println("\n\ntest2") test2() - println("\n\ntest3") - test3() initSignal() } @@ -288,24 +285,3 @@ func test2() { } println("error: %v", err) } -func test3() { - var appName = "UserProviderGer" - var referenceConfig = config.ReferenceConfig{ - InterfaceName: "com.ikurento.user.UserProvider", - Cluster: "failover", - Registry: "hangzhouzk", - Protocol: dubbo.DUBBO, - Generic: true, - } - referenceConfig.GenericLoad(appName) //appName is the unique identification of RPCService - - time.Sleep(3 * time.Second) - println("\n\n\nstart to generic invoke") - resp, err := referenceConfig.GetRPCService().(*config.GenericService).Invoke([]interface{}{"GetUser", []string{"java.lang.String"}, []interface{}{"A003"}}) - if err != nil { - panic(err) - } - println("res: %v\n", resp) - println("succ!") - -} diff --git a/examples/generic/go-client/app/client.go b/examples/generic/go-client/app/client.go new file mode 100644 index 0000000000000000000000000000000000000000..8d5a1bc5fa6cb186fcf456d385f8dad16b750ea3 --- /dev/null +++ b/examples/generic/go-client/app/client.go @@ -0,0 +1,100 @@ +/* + * 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" + "time" +) + +import ( + _ "github.com/apache/dubbo-go/common/proxy/proxy_factory" + "github.com/apache/dubbo-go/config" + "github.com/apache/dubbo-go/protocol/dubbo" + _ "github.com/apache/dubbo-go/registry/protocol" + + _ "github.com/apache/dubbo-go/filter/impl" + + _ "github.com/apache/dubbo-go/cluster/cluster_impl" + _ "github.com/apache/dubbo-go/cluster/loadbalance" + _ "github.com/apache/dubbo-go/registry/zookeeper" +) + +var ( + survivalTimeout int = 10e9 +) + +// they are necessary: +// export CONF_CONSUMER_FILE_PATH="xxx" +// export APP_LOG_CONF_FILE="xxx" +func main() { + println("\n\ntest") + test() + println("\n\ntest2") + test2() + +} +func test() { + var appName = "UserProviderGer" + var referenceConfig = config.ReferenceConfig{ + InterfaceName: "com.ikurento.user.UserProvider", + Cluster: "failover", + Registry: "hangzhouzk", + Protocol: dubbo.DUBBO, + Generic: true, + } + referenceConfig.GenericLoad(appName) //appName is the unique identification of RPCService + + time.Sleep(3 * time.Second) + println("\n\n\nstart to generic invoke") + resp, err := referenceConfig.GetRPCService().(*config.GenericService).Invoke([]interface{}{"GetUser", []string{"java.lang.String"}, []interface{}{"A003"}}) + if err != nil { + panic(err) + } + fmt.Printf("res: %+v\n", resp) + println("succ!") + +} +func test2() { + var appName = "UserProviderGer" + var referenceConfig = config.ReferenceConfig{ + InterfaceName: "com.ikurento.user.UserProvider", + Cluster: "failover", + Registry: "hangzhouzk", + Protocol: dubbo.DUBBO, + Generic: true, + } + referenceConfig.GenericLoad(appName) //appName is the unique identification of RPCService + + time.Sleep(3 * time.Second) + println("\n\n\nstart to generic invoke") + user := User{ + Id: "3213", + Name: "panty", + Age: 25, + Time: time.Now(), + Sex: Gender(MAN), + } + resp, err := referenceConfig.GetRPCService().(*config.GenericService).Invoke([]interface{}{"queryUser", []string{"com.ikurento.user.User"}, []interface{}{user}}) + if err != nil { + panic(err) + } + fmt.Printf("res: %+v\n", resp) + println("succ!") + +} diff --git a/examples/generic/go-client/app/user.go b/examples/generic/go-client/app/user.go new file mode 100644 index 0000000000000000000000000000000000000000..9b226e24456e850f1b31fc0501e04d573cec35fd --- /dev/null +++ b/examples/generic/go-client/app/user.go @@ -0,0 +1,57 @@ +package main + +import ( + "strconv" + "time" +) +import ( + hessian "github.com/apache/dubbo-go-hessian2" +) + +type Gender hessian.JavaEnum + +const ( + MAN hessian.JavaEnum = iota + WOMAN +) + +var genderName = map[hessian.JavaEnum]string{ + MAN: "MAN", + WOMAN: "WOMAN", +} + +var genderValue = map[string]hessian.JavaEnum{ + "MAN": MAN, + "WOMAN": WOMAN, +} + +func (g Gender) JavaClassName() string { + return "com.ikurento.user.Gender" +} + +func (g Gender) String() string { + s, ok := genderName[hessian.JavaEnum(g)] + if ok { + return s + } + + return strconv.Itoa(int(g)) +} + +func (g Gender) EnumValue(s string) hessian.JavaEnum { + v, ok := genderValue[s] + if ok { + return v + } + + return hessian.InvalidJavaEnum +} + +type User struct { + // !!! Cannot define lowercase names of variable + Id string + Name string + Age int32 + Time time.Time + Sex Gender // 娉ㄦ剰姝ゅ锛宩ava enum Object <--> go string +} diff --git a/examples/generic/go-client/assembly/bin/load.sh b/examples/generic/go-client/assembly/bin/load.sh new file mode 100644 index 0000000000000000000000000000000000000000..07d5d15eac7b7974845e36c3807e7ec55875de65 --- /dev/null +++ b/examples/generic/go-client/assembly/bin/load.sh @@ -0,0 +1,196 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : dubbogo app devops script +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-05-13 02:01 +# FILE : load.sh +# ****************************************************** + +APP_NAME="APPLICATION_NAME" +APP_ARGS="" +SLEEP_INTERVAL=5 +MAX_LIFETIME=4000 + +PROJECT_HOME="" +OS_NAME=`uname` +if [[ ${OS_NAME} != "Windows" ]]; then + PROJECT_HOME=`pwd` + PROJECT_HOME=${PROJECT_HOME}"/" +else + APP_NAME="APPLICATION_NAME.exe" +fi + +export CONF_CONSUMER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE" +export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE" +# export GOTRACEBACK=system +# export GODEBUG=gctrace=1 + +usage() { + echo "Usage: $0 start [conf suffix]" + echo " $0 stop" + echo " $0 term" + echo " $0 restart" + echo " $0 list" + echo " $0 monitor" + echo " $0 crontab" + exit +} + +start() { + arg=$1 + if [ "$arg" = "" ];then + echo "No registry type! Default client.yml!" + else + export CONF_CONSUMER_FILE_PATH=${CONF_CONSUMER_FILE_PATH//\.yml/\_$arg\.yml} + fi + if [ ! -f "${CONF_CONSUMER_FILE_PATH}" ];then + echo $CONF_CONSUMER_FILE_PATH" is not existing!" + return + fi + APP_LOG_PATH=${PROJECT_HOME}"logs/" + mkdir -p ${APP_LOG_PATH} + APP_BIN=${PROJECT_HOME}sbin/${APP_NAME} + chmod u+x ${APP_BIN} + # CMD="nohup ${APP_BIN} ${APP_ARGS} >>${APP_NAME}.nohup.out 2>&1 &" + CMD="${APP_BIN}" + eval ${CMD} + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` + if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` + fi + CUR=`date +%FT%T` + if [ "${PID}" != "" ]; then + for p in ${PID} + do + echo "start ${APP_NAME} ( pid =" ${p} ") at " ${CUR} + done + fi +} + +stop() { + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` + if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` + fi + if [ "${PID}" != "" ]; + then + for ps in ${PID} + do + echo "kill -SIGINT ${APP_NAME} ( pid =" ${ps} ")" + kill -2 ${ps} + done + fi +} + + +term() { + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` + if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` + fi + if [ "${PID}" != "" ]; + then + for ps in ${PID} + do + echo "kill -9 ${APP_NAME} ( pid =" ${ps} ")" + kill -9 ${ps} + done + fi +} + +list() { + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s\n", $1, $2, $9, $10)}'` + if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{printf("%s,%s,%s,%s,%s\n", $1, $4, $6, $7, $8)}'` + fi + + if [ "${PID}" != "" ]; then + echo "list ${APP_NAME}" + + if [[ ${OS_NAME} == "Linux" || ${OS_NAME} == "Darwin" ]]; then + echo "index: user, pid, start, duration" + else + echo "index: PID, WINPID, UID, STIME, COMMAND" + fi + idx=0 + for ps in ${PID} + do + echo "${idx}: ${ps}" + ((idx ++)) + done + fi +} + +monitor() { + idx=0 + while true; do + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` + if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` + fi + if [[ "${PID}" == "" ]]; then + start + idx=0 + fi + + ((LIFE=idx*${SLEEP_INTERVAL})) + echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds." + ((idx ++)) + sleep ${SLEEP_INTERVAL} + done +} + +crontab() { + idx=0 + while true; do + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $2}'` + if [[ ${OS_NAME} != "Linux" && ${OS_NAME} != "Darwin" ]]; then + PID=`ps aux | grep -w ${APP_NAME} | grep -v grep | awk '{print $1}'` + fi + if [[ "${PID}" == "" ]]; then + start + idx=0 + fi + + ((LIFE=idx*${SLEEP_INTERVAL})) + echo "${APP_NAME} ( pid = " ${PID} ") has been working in normal state for " $LIFE " seconds." + ((idx ++)) + sleep ${SLEEP_INTERVAL} + if [[ ${LIFE} -gt ${MAX_LIFETIME} ]]; then + kill -9 ${PID} + fi + done +} + +opt=$1 +case C"$opt" in + Cstart) + start $2 + ;; + Cstop) + stop + ;; + Cterm) + term + ;; + Crestart) + term + start $2 + ;; + Clist) + list + ;; + Cmonitor) + monitor + ;; + Ccrontab) + crontab + ;; + C*) + usage + ;; +esac + diff --git a/examples/generic/go-client/assembly/common/app.properties b/examples/generic/go-client/assembly/common/app.properties new file mode 100644 index 0000000000000000000000000000000000000000..6bbd6db850ceeaf5ff873fee01a3578237cbd557 --- /dev/null +++ b/examples/generic/go-client/assembly/common/app.properties @@ -0,0 +1,17 @@ +# dubbogo application configure script +# ****************************************************** +# DESC : dubbogo environment variable +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:29 +# FILE : app.properties +# ****************************************************** + +export TARGET_EXEC_NAME="user_info_client" +# BUILD_PACKAGE="dubbogo-examples/user-info/client/app" +export BUILD_PACKAGE="app" + +export TARGET_CONF_FILE="conf/client.yml" +export TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/generic/go-client/assembly/common/build.sh b/examples/generic/go-client/assembly/common/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..e72418297ad2f0ac6985476b5a8d5e03b9e7584e --- /dev/null +++ b/examples/generic/go-client/assembly/common/build.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:28 +# FILE : build.sh +# ****************************************************** + +rm -rf target/ + +PROJECT_HOME=`pwd` +TARGET_FOLDER=${PROJECT_HOME}/target/${GOOS} + +TARGET_SBIN_NAME=${TARGET_EXEC_NAME} +version=`cat app/version.go | grep Version | grep -v "Apache" | awk -F '=' '{print $2}' | awk -F '"' '{print $2}'` +if [[ ${GOOS} == "windows" ]]; then + TARGET_SBIN_NAME=${TARGET_SBIN_NAME}.exe +fi +TARGET_NAME=${TARGET_FOLDER}/${TARGET_SBIN_NAME} +if [[ $PROFILE == "dev" || $PROFILE == "test" ]]; then + # GFLAGS=-gcflags "-N -l" -race -x -v # -x浼氭妸go build鐨勮缁嗚繃绋嬭緭鍑� + # GFLAGS=-gcflags "-N -l" -race -v + # GFLAGS="-gcflags \"-N -l\" -v" + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd - +else + # -s鍘绘帀绗﹀彿琛紙鐒跺悗panic鏃跺€欑殑stack trace灏辨病鏈変换浣曟枃浠跺悕/琛屽彿淇℃伅浜嗭紝杩欎釜绛変环浜庢櫘閫欳/C++绋嬪簭琚玸trip鐨勬晥鏋滐級锛� + # -w鍘绘帀DWARF璋冭瘯淇℃伅锛屽緱鍒扮殑绋嬪簭灏变笉鑳界敤gdb璋冭瘯浜嗐€�-s鍜�-w涔熷彲浠ュ垎寮€浣跨敤锛屼竴鑸潵璇村鏋滀笉鎵撶畻鐢╣db璋冭瘯锛� + # -w鍩烘湰娌″暐鎹熷け銆�-s鐨勬崯澶卞氨鏈夌偣澶т簡銆� + cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-w" -x -v -i -o ${TARGET_NAME} && cd - +fi + +TAR_NAME=${TARGET_EXEC_NAME}-${version}-`date "+%Y%m%d-%H%M"`-${PROFILE} + +mkdir -p ${TARGET_FOLDER}/${TAR_NAME} + +SBIN_DIR=${TARGET_FOLDER}/${TAR_NAME}/sbin +BIN_DIR=${TARGET_FOLDER}/${TAR_NAME} +CONF_DIR=${TARGET_FOLDER}/${TAR_NAME}/conf + +mkdir -p ${SBIN_DIR} +mkdir -p ${CONF_DIR} + +mv ${TARGET_NAME} ${SBIN_DIR} +cp -r assembly/bin ${BIN_DIR} +cd ${BIN_DIR}/bin/ && mv load.sh load_${TARGET_EXEC_NAME}.sh && cd - + +platform=$(uname) +# modify APPLICATION_NAME +if [ ${platform} == "Darwin" ]; then + sed -i "" "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* +else + sed -i "s~APPLICATION_NAME~${TARGET_EXEC_NAME}~g" ${BIN_DIR}/bin/* +fi + +# modify TARGET_CONF_FILE +if [ ${platform} == "Darwin" ]; then + sed -i "" "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* +else + sed -i "s~TARGET_CONF_FILE~${TARGET_CONF_FILE}~g" ${BIN_DIR}/bin/* +fi + +# modify TARGET_LOG_CONF_FILE +if [ ${platform} == "Darwin" ]; then + sed -i "" "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* +else + sed -i "s~TARGET_LOG_CONF_FILE~${TARGET_LOG_CONF_FILE}~g" ${BIN_DIR}/bin/* +fi + +cp -r profiles/${PROFILE}/* ${CONF_DIR} + +cd ${TARGET_FOLDER} + +tar czf ${TAR_NAME}.tar.gz ${TAR_NAME}/* + diff --git a/examples/generic/go-client/assembly/linux/dev.sh b/examples/generic/go-client/assembly/linux/dev.sh new file mode 100644 index 0000000000000000000000000000000000000000..3373f01b948b708cd7bc1958c9d56a9042c60a68 --- /dev/null +++ b/examples/generic/go-client/assembly/linux/dev.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for dev env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2017-10-18 13:24 +# FILE : dev.sh +# ****************************************************** + + +set -e + +export GOOS=linux +export GOARCH=amd64 + +export PROFILE="dev" + +PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/linux/release.sh b/examples/generic/go-client/assembly/linux/release.sh new file mode 100644 index 0000000000000000000000000000000000000000..34867b8b3488778cd76a1dc7802393dcab6b0df0 --- /dev/null +++ b/examples/generic/go-client/assembly/linux/release.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for release env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:34 +# FILE : test.sh +# ****************************************************** + + +set -e + +export GOOS=linux +export GOARCH=amd64 + +export PROFILE="release" +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/linux/test.sh b/examples/generic/go-client/assembly/linux/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bbbefd1e14e08c16deaf859e2841f4d1fe88e9c --- /dev/null +++ b/examples/generic/go-client/assembly/linux/test.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for test env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:34 +# FILE : test.sh +# ****************************************************** + + +set -e + +export GOOS=linux +export GOARCH=amd64 + +export PROFILE="test" +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/mac/dev.sh b/examples/generic/go-client/assembly/mac/dev.sh new file mode 100644 index 0000000000000000000000000000000000000000..b68ac83b6524a6713cd90c4fc5968fe64b1a9545 --- /dev/null +++ b/examples/generic/go-client/assembly/mac/dev.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for dev env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2017-10-18 13:24 +# FILE : dev.sh +# ****************************************************** + + +set -e + +export GOOS=darwin +export GOARCH=amd64 + +export PROFILE="dev" + +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/mac/release.sh b/examples/generic/go-client/assembly/mac/release.sh new file mode 100644 index 0000000000000000000000000000000000000000..688288b3b1b989e8af70a3674b34ea8e0668f3b4 --- /dev/null +++ b/examples/generic/go-client/assembly/mac/release.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for release env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:34 +# FILE : test.sh +# ****************************************************** + + +set -e + +export GOOS=darwin +export GOARCH=amd64 + +export PROFILE="release" +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/mac/test.sh b/examples/generic/go-client/assembly/mac/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..56d6c11ecd6a1dc5984c74b88c10be9239e57428 --- /dev/null +++ b/examples/generic/go-client/assembly/mac/test.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for test env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:34 +# FILE : test.sh +# ****************************************************** + + +set -e + +export GOOS=darwin +export GOARCH=amd64 + +export PROFILE="test" +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/windows/dev.sh b/examples/generic/go-client/assembly/windows/dev.sh new file mode 100644 index 0000000000000000000000000000000000000000..91cf6f23bcbecb26db798469a30529261aabbbb6 --- /dev/null +++ b/examples/generic/go-client/assembly/windows/dev.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for dev env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2017-10-18 13:24 +# FILE : dev.sh +# ****************************************************** + + +set -e + +export GOOS=linux +export GOARCH=amd64 + +export PROFILE="dev" +PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/windows/release.sh b/examples/generic/go-client/assembly/windows/release.sh new file mode 100644 index 0000000000000000000000000000000000000000..f317720bd53d9c9e5f8f484b6eb682c9c736af0c --- /dev/null +++ b/examples/generic/go-client/assembly/windows/release.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for release env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:34 +# FILE : test.sh +# ****************************************************** + + +set -e + +export GOOS=windows +export GOARCH=amd64 + +export PROFILE="release" +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/assembly/windows/test.sh b/examples/generic/go-client/assembly/windows/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..7dd2bec5260e647b57a46aaa37acc098babff068 --- /dev/null +++ b/examples/generic/go-client/assembly/windows/test.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# ****************************************************** +# DESC : build script for test env +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2016-07-12 16:34 +# FILE : test.sh +# ****************************************************** + + +set -e + +export GOOS=windows +export GOARCH=amd64 + +export PROFILE="test" +export PROJECT_HOME=`pwd` + +if [ -f "${PROJECT_HOME}/assembly/common/app.properties" ]; then + . ${PROJECT_HOME}/assembly/common/app.properties +fi + +if [ -f "${PROJECT_HOME}/assembly/common/build.sh" ]; then + sh ${PROJECT_HOME}/assembly/common/build.sh +fi diff --git a/examples/generic/go-client/profiles/dev/client.yml b/examples/generic/go-client/profiles/dev/client.yml new file mode 100644 index 0000000000000000000000000000000000000000..f4e3180aa88cbbdffd519d70b3cc83b2e2b6674a --- /dev/null +++ b/examples/generic/go-client/profiles/dev/client.yml @@ -0,0 +1,55 @@ +# 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 genric client" + version : "0.0.1" + owner : "ZX" + environment : "dev" + +registries : + "hangzhouzk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + "shanghaizk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + +references: + +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 2 + heartbeat_period: "5s" + session_timeout: "20s" + 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_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 10240 + session_name: "client" diff --git a/examples/generic/go-client/profiles/dev/log.yml b/examples/generic/go-client/profiles/dev/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..59fa4279ad85272c4c49d532beaf23b74d00f58a --- /dev/null +++ b/examples/generic/go-client/profiles/dev/log.yml @@ -0,0 +1,28 @@ + +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +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: diff --git a/examples/generic/go-client/profiles/release/client.yml b/examples/generic/go-client/profiles/release/client.yml new file mode 100644 index 0000000000000000000000000000000000000000..5a21bca6c93336a8888b55a6a7e81f9240c709a5 --- /dev/null +++ b/examples/generic/go-client/profiles/release/client.yml @@ -0,0 +1,55 @@ +# 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 generic client" + version : "0.0.1" + owner : "ZX" + environment : "release" + +registries : + "hangzhouzk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + "shanghaizk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + +references: + +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 2 + heartbeat_period: "5s" + session_timeout: "20s" + 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_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 10240 + session_name: "client" diff --git a/examples/generic/go-client/profiles/release/log.yml b/examples/generic/go-client/profiles/release/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..e0514be020eedf594d99d112183cdd5ce199e46d --- /dev/null +++ b/examples/generic/go-client/profiles/release/log.yml @@ -0,0 +1,28 @@ + +level: "warn" +development: true +disableCaller: true +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: diff --git a/examples/generic/go-client/profiles/test/client.yml b/examples/generic/go-client/profiles/test/client.yml new file mode 100644 index 0000000000000000000000000000000000000000..7442c64c71abf47db9c15d85c6bcd2ced8057e46 --- /dev/null +++ b/examples/generic/go-client/profiles/test/client.yml @@ -0,0 +1,55 @@ +# 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: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2181" + username: "" + password: "" + "shanghaizk": + protocol: "zookeeper" + timeout : "3s" + address: "127.0.0.1:2182" + username: "" + password: "" + +references: + +protocol_conf: + dubbo: + reconnect_interval: 0 + connection_number: 2 + heartbeat_period: "5s" + session_timeout: "20s" + 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_wq_size: 512 + tcp_read_timeout: "1s" + tcp_write_timeout: "5s" + wait_timeout: "1s" + max_msg_len: 10240 + session_name: "client" diff --git a/examples/generic/go-client/profiles/test/log.yml b/examples/generic/go-client/profiles/test/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..baee0b7248484e425f88f35ab128212c931ff85e --- /dev/null +++ b/examples/generic/go-client/profiles/test/log.yml @@ -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: diff --git a/examples/generic/java-server/build.sh b/examples/generic/java-server/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c197da639c1c1d9375e18c24dd73366c49deefe --- /dev/null +++ b/examples/generic/java-server/build.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# ****************************************************** +# EMAIL : alexstocks@foxmail.com +# FILE : build.sh +# ****************************************************** + +# mvn dependency:sources +mvn clean package -Dmaven.test.skip +# mvn -X clean compile package -DskipTests=true diff --git a/examples/generic/java-server/pom.xml b/examples/generic/java-server/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..975157865e59f24693d755dd20b0aac4b179a793 --- /dev/null +++ b/examples/generic/java-server/pom.xml @@ -0,0 +1,181 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>com.ikurento</groupId> + <artifactId>user-info-server</artifactId> + <packaging>jar</packaging> + <version>0.2.0</version> + <description>The demo provider module of dubbo project</description> + <properties> + <skip_maven_deploy>false</skip_maven_deploy> + + <dubbo-version>2.6.5</dubbo-version> + <dubbo-jsonrpc-version>1.0.1</dubbo-jsonrpc-version> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>dubbo-dependencies-bom</artifactId> + <version>${dubbo-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.25</version> + </dependency> + + <dependency> + <groupId>com.alibaba</groupId> + <artifactId>dubbo</artifactId> + <version>${dubbo-version}</version> + <exclusions> + </exclusions> + </dependency> + + <dependency> + <groupId>io.netty</groupId> + <artifactId>netty-all</artifactId> + </dependency> + <dependency> + <groupId>org.apache.curator</groupId> + <artifactId>curator-framework</artifactId> + <version>2.12.0</version> + </dependency> + + <dependency> + <groupId>com.qianmi</groupId> + <artifactId>dubbo-rpc-jsonrpc</artifactId> + <version>${dubbo-jsonrpc-version}</version> + <exclusions> + <exclusion> + <groupId>org.springframework</groupId> + <artifactId>spring</artifactId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + <version>6.1.26</version> + </dependency> + + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + <version>2.9.9</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + <version>2.9.9</version> + </dependency> + + <dependency> + <groupId>com.github.sgroschupf</groupId> + <artifactId>zkclient</artifactId> + <version>0.1</version> + <exclusions> + <exclusion> + <artifactId>org.apache.zookeeper</artifactId> + <groupId>zookeeper</groupId> + </exclusion> + </exclusions> + </dependency> + + <dependency> + <groupId>org.apache.zookeeper</groupId> + <artifactId>zookeeper</artifactId> + <version>3.4.14</version> + </dependency> + + </dependencies> + + <repositories> + <repository> + <id>nexus-aliyu</id> + <url>http://maven.aliyun.com/nexus/content/groups/public</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>nexus-aliyu</id> + <url>http://maven.aliyun.com/nexus/content/groups/public</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + + + <build> + + <plugins> + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack</id> + <phase>package</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>com.alibaba</groupId> + <artifactId>dubbo</artifactId> + <version>${dubbo-version}</version> + <outputDirectory>${project.build.directory}/dubbo</outputDirectory> + <includes>META-INF/assembly/**</includes> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <id>make-assembly</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + <configuration> + <descriptors> + <descriptor>src/main/assembly/assembly.xml</descriptor> + </descriptors> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + + +</project> + + diff --git a/examples/generic/java-server/script/debug.sh b/examples/generic/java-server/script/debug.sh new file mode 100644 index 0000000000000000000000000000000000000000..27c5d800d846018127e762944151aa8e9ad4495d --- /dev/null +++ b/examples/generic/java-server/script/debug.sh @@ -0,0 +1,16 @@ +#!/us1r/bin/env bash +# ****************************************************** +# DESC : +# AUTHOR : Alex Stocks +# VERSION : 1.0 +# LICENCE : Apache License 2.0 +# EMAIL : alexstocks@foxmail.com +# MOD : 2017-10-09 21:52 +# FILE : to debug user info dubbo server +# ****************************************************** + +# jdb -classpath /Users/alex/tmp/us/conf:/Users/alex/tmp/us/lib/*:/Users/alex/test/java/dubbo/2.5.4/dubbo-remoting/dubbo-remoting-api/src/main/java/ com.alibaba.dubbo.container.Main +jdb -classpath /Users/alex/tmp/us/conf:/Users/alex/tmp/us/lib/* -sourcepath /Users/alex/test/java/dubbo/2.5.4/dubbo-remoting/dubbo-remoting-api/src/main/java/:/Users/alex/tmp/java-server/src/main/java com.alibaba.dubbo.container.Main +# jdb stop at com.alibaba.dubbo.remoting.exchange.codec.ExchangeCodec:76 +# run + diff --git a/examples/generic/java-server/src/main/assembly/assembly.xml b/examples/generic/java-server/src/main/assembly/assembly.xml new file mode 100644 index 0000000000000000000000000000000000000000..2f01fea20f5391112cccb88c87bfe4ae1b59750a --- /dev/null +++ b/examples/generic/java-server/src/main/assembly/assembly.xml @@ -0,0 +1,45 @@ +<!-- + - Copyright 1999-2011 Alibaba Group. + - + - Licensed 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. +--> +<assembly> + <id>assembly</id> + <formats> + <format>tar.gz</format> + </formats> + <includeBaseDirectory>true</includeBaseDirectory> + <fileSets> + <fileSet> + <directory>${project.build.directory}/dubbo/META-INF/assembly/bin</directory> + <outputDirectory>bin</outputDirectory> + <fileMode>0755</fileMode> + <directoryMode>0755</directoryMode> + </fileSet> + <fileSet> + <directory>src/main/assembly/conf</directory> + <includes> + <include>dubbo.properties</include> + <include>log4j.*</include> + </includes> + <outputDirectory>conf</outputDirectory> + <fileMode>0644</fileMode> + <directoryMode>0755</directoryMode> + </fileSet> + </fileSets> + <dependencySets> + <dependencySet> + <outputDirectory>lib</outputDirectory> + </dependencySet> + </dependencySets> +</assembly> \ No newline at end of file diff --git a/examples/generic/java-server/src/main/assembly/conf/dubbo.properties b/examples/generic/java-server/src/main/assembly/conf/dubbo.properties new file mode 100644 index 0000000000000000000000000000000000000000..2826f31303717256725b02a79e1698043709d2f3 --- /dev/null +++ b/examples/generic/java-server/src/main/assembly/conf/dubbo.properties @@ -0,0 +1,14 @@ +### dubbo娉ㄥ唽涓績閰嶇疆 ## +dubbo.container = log4j,spring +dubbo.application.name = user-info-server +dubbo.application.environment = product +dubbo.application.owner = AlexStocks +dubbo.registry.address = 127.0.0.1:2181 +dubbo.registry.protocol = zookeeper +dubbo.consumer.timeout = 10000 +dubbo.provider.timeout = 10000 +dubbo.protocol.name = dubbo +dubbo.protocol.port = 10000 + +dubbo.log4j.file = logs/dubbo.log +dubbo.log4j.level = INFO diff --git a/examples/generic/java-server/src/main/assembly/conf/log4j.properties b/examples/generic/java-server/src/main/assembly/conf/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..13c80493329261ea677de77624b363bf99c82652 --- /dev/null +++ b/examples/generic/java-server/src/main/assembly/conf/log4j.properties @@ -0,0 +1,20 @@ +## Logger configure file for myproject +log.dir=logs/ +datestamp=yyyy-MM-dd/HH:mm:ss.SSS + +log4j.rootLogger=DEBUG, file, console + +log4j.appender.file=org.apache.log4j.DailyRollingFileAppender +log4j.appender.file.threshold=DEBUG +log4j.appender.file.File=${log.dir}/log4j.log +log4j.appender.file.DatePattern=-yyyyMMddHH +log4j.appender.file.ImmediateFlush=true +log4j.appender.file.Append=true +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{${datestamp}} %5p: %l - %m%n + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.Threshold=DEBUG +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{${datestamp}} %5p: %l - %m%n + diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/Gender.java b/examples/generic/java-server/src/main/java/com/ikurento/user/Gender.java new file mode 100644 index 0000000000000000000000000000000000000000..72c30ae8d4bae8fc71b4cb598205141b2d1d2020 --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/Gender.java @@ -0,0 +1,6 @@ +package com.ikurento.user; + +public enum Gender { + MAN, + WOMAN +} diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/Provider.java b/examples/generic/java-server/src/main/java/com/ikurento/user/Provider.java new file mode 100644 index 0000000000000000000000000000000000000000..0031f5569fd5f16ded0da6e5426f78805fad4a42 --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/Provider.java @@ -0,0 +1,33 @@ +/* + * 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 com.ikurento.user; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Provider { + + /** + * To get ipv6 address to work, add + * System.setProperty("java.net.preferIPv6Addresses", "true"); + * before running your application. + */ + public static void main(String[] args) throws Exception { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo.provider.xml"}); + context.start(); + System.in.read(); // press any key to exit + } +} diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/Response.java b/examples/generic/java-server/src/main/java/com/ikurento/user/Response.java new file mode 100644 index 0000000000000000000000000000000000000000..3447e5c2537625f424b54291c53783a51922ae7b --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/Response.java @@ -0,0 +1,76 @@ +package com.ikurento.user; + +import java.io.*; +//import java.util.Objects; + +public final class Response<T> implements Serializable { + private static final long serialVersionUID = 3727205004706510648L; + public static final Integer OK = 200; + public static final Integer ERR = 500; + private Integer Status; + private String Err; + private T Data; + + public Response() { + } + + public static <T> Response<T> ok() { + Response r = new Response(); + r.Status = OK; + return r; + } + + public static <T> Response<T> ok(Object Data) { + Response r = new Response(); + r.Status = OK; + r.Data = Data; + return r; + } + + public static <T> Response<T> notOk(String Err) { + Response r = new Response(); + r.Status = ERR; + r.Err = Err; + return r; + } + + public static <T> Response<T> notOk(Integer Status, String Err) { + Response r = new Response(); + r.Status = Status; + r.Err = Err; + return r; + } + +// public Boolean isSuccess() { +// return Objects.equals(this.Status, OK); +// } + + public Integer getStatus() { + return this.Status; + } + + public void setStatus(Integer Status) { + this.Status = Status; + } + + public String getErr() { + return this.Err; + } + + public void setErr(String Err) { + this.Err = Err; + } + + public T getData() { + return this.Data; + } + + public void setData(T Data) { + this.Status = OK; + this.Data = Data; + } + + public String toString() { + return "Response{Status=" + this.Status + ", Err='" + this.Err + '\'' + ", Data=" + this.Data + '}'; + } +} \ No newline at end of file diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/User.java b/examples/generic/java-server/src/main/java/com/ikurento/user/User.java new file mode 100644 index 0000000000000000000000000000000000000000..eafc0fe1c0e0c7b72a0fce73b6a333668797145e --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/User.java @@ -0,0 +1,79 @@ +package com.ikurento.user; +// ref: https://github.com/JoeCao/dubbo_jsonrpc_example/tree/master/dubbo_server/src/main/java/com/ofpay/demo/api + +import java.util.Date; +import java.io.Serializable; + +public class User implements Serializable { + + private String id; + + private String name; + + private int age; + + private Date time = new Date(); + + private Gender sex = Gender.MAN; + + public User() { + } + + public User(String id, String name, int age) { + this.id = id; + this.name = name; + this.age = age; + } + + public User(String id, String name, int age, Date time, Gender sex) { + this.id = id; + this.name = name; + this.age = age; + this.time = time; + this.sex = sex; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } + + public Gender getSex() { + return sex; + } + + public void setSex(Gender sex) { + this.sex = sex; + } + + public String toString() { + return "User{id:" + id + ", name:" + name + ", age:" + age + ", time:" + time + ", gender:" + sex + "}"; + } +} diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/UserProvider.java b/examples/generic/java-server/src/main/java/com/ikurento/user/UserProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..24567d23be662312a4750f07b605c685a8dfa5fe --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/UserProvider.java @@ -0,0 +1,32 @@ +package com.ikurento.user; +// https://github.com/JoeCao/dubbo_jsonrpc_example/tree/master/dubbo_server/src/main/java/com/ofpay/demo/api + +import java.util.List; +import java.util.Map; + +public interface UserProvider { + + boolean isLimit(Gender gender, String name); + + User GetUser(String userId); // the first alpha is Upper case to compatible with golang. + + List<User> GetUsers(List<String> userIdList); + + void GetUser3(); + + User GetUser0(String userId, String name); + + User GetErr(String userId) throws Exception; + + Map<String, User> GetUserMap(List<String> userIdList); + + User getUser(int usercode); + + User queryUser(User user); + + Map<String, User> queryAll(); + + int Calc(int a,int b); + + Response<Integer> Sum(int a, int b); +} diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/UserProviderAnotherImpl.java b/examples/generic/java-server/src/main/java/com/ikurento/user/UserProviderAnotherImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..d600545c5084a40f1318e47a6a1c20bfcd6d36bc --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/UserProviderAnotherImpl.java @@ -0,0 +1,121 @@ +package com.ikurento.user; +//ref: https://github.com/JoeCao/dubbo_jsonrpc_example/tree/master/dubbo_server/src/main/java/com/ofpay/demo/api + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +// import org.apache.log4j.Logger; +// import org.apache.log4j.LoggerFactory; + +import java.util.*; + +public class UserProviderAnotherImpl implements UserProvider { + // private static final Logger logger = LoggerFactory.getLogger(getClass()); // 鍙緭鍑哄埌dubbo鐨刲og(logs/server.log) + private static final Logger logger = LoggerFactory.getLogger("userLogger"); // 杈撳嚭鍒皍ser-server.log + + private Map<String, User> userMap = new HashMap<String, User>(); + + public UserProviderAnotherImpl() { + // userMap.put("001", new User("001", "other-zhangsan", 18, new Date(1998-1900, 1, 2, 3, 4, 5), Gender.MAN)); + userMap.put("001", new User("001", "other-zhangsan", 18, new Date(0x12345678), Gender.MAN)); + userMap.put("002", new User("002", "other-lisi", 20, new Date(1996-1900, 1, 2, 3, 4, 5), Gender.MAN)); + userMap.put("003", new User("003", "other-lily", 23, new Date(1993-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); + userMap.put("004", new User("004", "other-lisa", 32, new Date(1985-1900, 1, 2, 3, 4, 5), Gender.WOMAN)); + } + + public boolean isLimit(Gender gender, String name) { + logger.info(String.format("input gender=%sand name=%s", gender, name)); + return Gender.MAN == gender; + } + + public User GetUser(String userId) { + logger.info("input userId = " + userId); + return new User(userId, "Joe", 48); + } + + public User GetUser0(String userId, String name) { + return new User(userId, name, 48); + } + public void GetUser3() { + } + public User GetErr(String userId) throws Exception { + throw new Exception("exception"); + } + public List<User> GetUsers(ArrayList<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + logger.info("id:" + id + ", user:" + userMap.get(id)); + } + } + + return userList; + } + + public Map<String, User> GetUserMap(List<String> userIdList) { + Iterator it = userIdList.iterator(); + Map<String, User> map = new HashMap<String, User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + map.put(id, userMap.get(id)); + logger.info("id:" + id + ", user:" + userMap.get(id)); + } + } + + return map; + } + + public List<User> GetUsers(List<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + logger.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + logger.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + logger.info("id:" + id + ", user:" + userMap.get(id)); + } + } + + return userList; + } + + // @Override + public User getUser(int userCode) { + logger.info("input userCode = " + userCode); + return new User(String.valueOf(userCode), "userCode get", 48); + } + + public User queryUser(User user) { + logger.info("input user = " + user); + return new User(user.getId(), "get:" + user.getName(), user.getAge() + 18); + } + + public Map<String, User> queryAll() { + logger.info("input"); + Map<String, User> map = new HashMap<String, User>(); + map.put("001", new User("001", "Joe", 18)); + map.put("002", new User("002", "Wen", 20)); + + return map; + } + + public int Calc(int a,int b) { + return a + b + 100; + } + + public Response<Integer> Sum(int a,int b) { + return Response.ok(a+b); + } +} diff --git a/examples/generic/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java b/examples/generic/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..47a4e2d9732aa8d8d9279d47af5bb4fb3db37195 --- /dev/null +++ b/examples/generic/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java @@ -0,0 +1,100 @@ +package com.ikurento.user; + +// ref: https://github.com/JoeCao/dubbo_jsonrpc_example/tree/master/dubbo_server/src/main/java/com/ofpay/demo/api + +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.Iterator; + +// import org.apache.log4j.Logger; +// import org.apache.log4j.LoggerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UserProviderImpl implements UserProvider { + // private static final Logger logger = LoggerFactory.getLogger(getClass()); // 鍙緭鍑哄埌dubbo鐨刲og(logs/server.log) + private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); // 杈撳嚭鍒皍ser-server.log + Map<String, User> userMap = new HashMap<String, User>(); + + public UserProviderImpl() { + userMap.put("A001", new User("A001", "demo-zhangsan", 18)); + userMap.put("A002", new User("A002", "demo-lisi", 20)); + userMap.put("A003", new User("A003", "demo-lily", 23)); + userMap.put("A004", new User("A004", "demo-lisa", 32)); + } + + public boolean isLimit(Gender gender, String name) { + return Gender.WOMAN == gender; + } + + public User GetUser(String userId) { + return new User(userId, "zhangsan", 18); + } + public User GetErr(String userId) throws Exception { + throw new Exception("exception"); + } + public User GetUser0(String userId, String name) { + return new User(userId, name, 18); + } + + public List<User> GetUsers(List<String> userIdList) { + Iterator it = userIdList.iterator(); + List<User> userList = new ArrayList<User>(); + LOG.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + LOG.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + userList.add(userMap.get(id)); + LOG.info("id:" + id + ", user:" + userMap.get(id)); + } + } + + return userList; + } + + public void GetUser3() { + } + + public Map<String, User> GetUserMap(List<String> userIdList) { + Iterator it = userIdList.iterator(); + Map<String, User> map = new HashMap<String, User>(); + LOG.warn("@userIdList size:" + userIdList.size()); + + while(it.hasNext()) { + String id = (String)(it.next()); + LOG.info("GetUsers(@uid:" + id + ")"); + if (userMap.containsKey(id)) { + map.put(id, userMap.get(id)); + LOG.info("id:" + id + ", user:" + userMap.get(id)); + } + } + + return map; + } + + public User queryUser(User user) { + return new User(user.getId(), "hello:" +user.getName(), user.getAge() + 18); + } + + public Map<String, User> queryAll() { + return userMap; + } + + + public User getUser(int userCode) { + return new User(String.valueOf(userCode), "userCode get", 48); + } + + + public int Calc(int a,int b) { + return a + b; + } + + public Response<Integer> Sum(int a,int b) { + return Response.ok(a+b); + } +} diff --git a/examples/generic/java-server/src/main/resources/META-INF/spring/dubbo.provider.xml b/examples/generic/java-server/src/main/resources/META-INF/spring/dubbo.provider.xml new file mode 100644 index 0000000000000000000000000000000000000000..f8dd13a833e6095485d0504e21cec272a3c9a288 --- /dev/null +++ b/examples/generic/java-server/src/main/resources/META-INF/spring/dubbo.provider.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + - Copyright 1999-2011 Alibaba Group. + - + - Licensed 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd + http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> + + <!-- 搴旂敤鍚� --> + <dubbo:application name="user-info-server"/> + <!-- 杩炴帴鍒板摢涓湰鍦版敞鍐屼腑蹇� --> + <dubbo:registry id="ikurento" address="zookeeper://127.0.0.1:2181" /> + <dubbo:registry id="ikurento2" address="zookeeper://127.0.0.1:2182" /> + <!-- 鐢╠ubbo鍗忚鍦�20880绔彛鏆撮湶鏈嶅姟 --> + <!-- dubbo:protocol host="127.0.0.1" / --> + <dubbo:protocol id="dubbo" name="dubbo" host="127.0.0.1" port="20010" /> + <dubbo:protocol id="jsonrpc" name="jsonrpc" host="127.0.0.1" port="10010" /> + <!-- 澹版槑闇€瑕佹毚闇茬殑鏈嶅姟鎺ュ彛 --> + <dubbo:service id="aaa" registry="ikurento" timeout="3000" interface="com.ikurento.user.UserProvider" ref="demoService"/> + <dubbo:service id="bbb" registry="ikurento" timeout="3000" interface="com.ikurento.user.UserProvider" ref="otherService" version="2.0"/> + <dubbo:service id="ccc" registry="ikurento" timeout="3000" interface="com.ikurento.user.UserProvider" ref="otherService" group="as" version="2.0"/> + + <bean id="demoService" class="com.ikurento.user.UserProviderImpl" /> + <bean id="otherService" class="com.ikurento.user.UserProviderAnotherImpl"/> + +</beans> diff --git a/examples/generic/java-server/src/main/resources/log4j.properties b/examples/generic/java-server/src/main/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..13c80493329261ea677de77624b363bf99c82652 --- /dev/null +++ b/examples/generic/java-server/src/main/resources/log4j.properties @@ -0,0 +1,20 @@ +## Logger configure file for myproject +log.dir=logs/ +datestamp=yyyy-MM-dd/HH:mm:ss.SSS + +log4j.rootLogger=DEBUG, file, console + +log4j.appender.file=org.apache.log4j.DailyRollingFileAppender +log4j.appender.file.threshold=DEBUG +log4j.appender.file.File=${log.dir}/log4j.log +log4j.appender.file.DatePattern=-yyyyMMddHH +log4j.appender.file.ImmediateFlush=true +log4j.appender.file.Append=true +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{${datestamp}} %5p: %l - %m%n + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.Threshold=DEBUG +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{${datestamp}} %5p: %l - %m%n + diff --git a/examples/helloworld/dubbo/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java b/examples/helloworld/dubbo/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java index d57ae54e386c981656ab68c1133dd37a9cc6711a..4a394b80a4b767f25e2ff13b2d4cfe7a500f759a 100644 --- a/examples/helloworld/dubbo/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java +++ b/examples/helloworld/dubbo/java-server/src/main/java/com/ikurento/user/UserProviderImpl.java @@ -6,7 +6,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class UserProviderImpl implements UserProvider { - private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); // Output to user埌user-server.log + private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); //Output to user-server.log public User GetUser(String userId) { return new User(userId, "zhangsan", 18);