You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by wa...@apache.org on 2020/11/01 11:46:23 UTC
[dubbo-go-samples] branch tag_router created (now 953673d)
This is an automated email from the ASF dual-hosted git repository.
watermelo pushed a change to branch tag_router
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git.
at 953673d Add: tag router examples
This branch includes the following new commits:
new 953673d Add: tag router examples
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[dubbo-go-samples] 01/01: Add: tag router examples
Posted by wa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
watermelo pushed a commit to branch tag_router
in repository https://gitbox.apache.org/repos/asf/dubbo-go-samples.git
commit 953673d4f0e77c2a398560e9d2696119ca1baa7a
Author: watermelon <80...@qq.com>
AuthorDate: Sun Nov 1 19:45:53 2020 +0800
Add: tag router examples
---
router/{condition => }/README.md | 18 +-
router/tag/go-client/app/client.go | 127 +++++++++++
router/tag/go-client/assembly/bin/load.sh | 203 +++++++++++++++++
.../tag/go-client/assembly/common/app.properties | 24 ++
router/tag/go-client/assembly/common/build.sh | 89 ++++++++
router/tag/go-client/assembly/linux/dev.sh | 36 +++
router/tag/go-client/assembly/linux/release.sh | 35 +++
router/tag/go-client/assembly/linux/test.sh | 35 +++
router/tag/go-client/assembly/mac/dev.sh | 36 +++
router/tag/go-client/assembly/mac/release.sh | 34 +++
router/tag/go-client/assembly/mac/test.sh | 34 +++
router/tag/go-client/assembly/windows/dev.sh | 34 +++
router/tag/go-client/assembly/windows/release.sh | 34 +++
router/tag/go-client/assembly/windows/test.sh | 34 +++
router/tag/go-client/profiles/dev/client.yml | 62 +++++
router/tag/go-client/profiles/dev/log.yml | 28 +++
.../tag/go-client/profiles/dev/router_config.yml | 14 ++
router/tag/go-server/app/server.go | 78 +++++++
router/tag/go-server/app/user.go | 60 +++++
router/tag/go-server/app/version.go | 22 ++
router/tag/go-server/assembly/bin/load.sh | 151 +++++++++++++
.../tag/go-server/assembly/common/app.properties | 23 ++
router/tag/go-server/assembly/common/build.sh | 80 +++++++
router/tag/go-server/assembly/linux/dev.sh | 36 +++
router/tag/go-server/assembly/linux/release.sh | 36 +++
router/tag/go-server/assembly/linux/test.sh | 36 +++
router/tag/go-server/assembly/mac/dev.sh | 36 +++
router/tag/go-server/assembly/mac/release.sh | 36 +++
router/tag/go-server/assembly/mac/test.sh | 36 +++
router/tag/go-server/assembly/windows/dev.sh | 36 +++
router/tag/go-server/assembly/windows/release.sh | 36 +++
router/tag/go-server/assembly/windows/test.sh | 36 +++
router/tag/go-server/profiles/dev/log.yml | 28 +++
router/tag/go-server/profiles/dev/server.yml | 95 ++++++++
router/tag/java-client/build.sh | 21 ++
router/tag/java-client/pom.xml | 211 +++++++++++++++++
.../tag/java-client/src/main/assembly/assembly.xml | 43 ++++
.../src/main/java/com/ikurento/user/Consumer.java | 61 +++++
.../java/com/ikurento/user/EmbeddedZooKeeper.java | 250 +++++++++++++++++++++
.../src/main/java/com/ikurento/user/User.java | 76 +++++++
.../main/java/com/ikurento/user/UserProvider.java | 18 ++
.../src/main/java/com/ikurento/user/ZKTools.java | 88 ++++++++
.../resources/META-INF/spring/dubbo.consumer.xml | 37 +++
.../src/main/resources/META-INF/spring/service.xml | 27 +++
.../src/main/resources/log4j.properties | 19 ++
router/tag/java-server/build.sh | 20 ++
router/tag/java-server/pom.xml | 210 +++++++++++++++++
router/tag/java-server/script/debug.sh | 23 ++
.../tag/java-server/src/main/assembly/assembly.xml | 43 ++++
.../java/com/ikurento/user/EmbeddedZooKeeper.java | 250 +++++++++++++++++++++
.../src/main/java/com/ikurento/user/Provider.java | 40 ++++
.../src/main/java/com/ikurento/user/Provider2.java | 40 ++++
.../src/main/java/com/ikurento/user/User.java | 86 +++++++
.../main/java/com/ikurento/user/UserProvider.java | 24 ++
.../src/main/java/com/ikurento/user/ZKTools.java | 89 ++++++++
.../com/ikurento/user/impl/UserProviderImpl.java | 32 +++
.../resources/META-INF/spring/dubbo.provider.xml | 34 +++
.../resources/META-INF/spring/dubbo.provider2.xml | 34 +++
.../src/main/resources/log4j.properties | 20 ++
59 files changed, 3526 insertions(+), 8 deletions(-)
diff --git a/router/condition/README.md b/router/README.md
similarity index 80%
rename from router/condition/README.md
rename to router/README.md
index 84be194..5889f14 100644
--- a/router/condition/README.md
+++ b/router/README.md
@@ -1,16 +1,19 @@
## 1.Run java server & java client following
[README](https://github.com/dubbogo/dubbogo-samples/blob/master/README.md)(You must run java program to initialize configuration in zookeeper)
-
-## 2.Use condition router feature
-### 2.1.with config file
-
+## 2.Use router feature
+
+### 2.1 use condition router with config file
+
Modify [router_config.yml](go-client/profiles/dev/router_config.yml) what you want to config
-
+
[How to write router_config.yml](http://dubbo.apache.org/en-us/docs/user/demos/routing-rule.html)
-### 2.2.with config center
+### 2.2 use tag router
+[How to use tag router](http://dubbo.apache.org/en-us/docs/user/demos/routing-rule.html)
+
+### 2.3 with config center
#### zookeeper
@@ -24,10 +27,9 @@ config_center:
```
Make sure dubbo-admin, dubbo-server and dubbo-client use the same zookeeper.
-
+
## 3.go client
Then start dubbo-go client following [README](https://github.com/dubbogo/dubbogo-samples/blob/master/README.md).
to check your router, enjoy it.
-
diff --git a/router/tag/go-client/app/client.go b/router/tag/go-client/app/client.go
new file mode 100644
index 0000000..9cd6107
--- /dev/null
+++ b/router/tag/go-client/app/client.go
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "os/signal"
+ "syscall"
+ "time"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ "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/directory"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+ gxlog "github.com/dubbogo/gost/log"
+
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/cluster/router/tag"
+ "github.com/apache/dubbo-go/common/constant"
+ _ "github.com/apache/dubbo-go/config_center/zookeeper"
+ _ "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"
+// export CONF_ROUTER_FILE_PATH="xxx"
+func main() {
+ hessian.RegisterPOJO(&User{})
+ config.Load()
+ time.Sleep(1e9)
+
+ gxlog.CInfo("\n\n\nstart to test dubbo")
+ user := &User{}
+ ctx := context.Background()
+ atm := map[string]string{
+ "dubbo.tag": "beijing",
+ "dubbo.force.tag": "true",
+ }
+ ctx = context.WithValue(ctx, constant.AttachmentKey, atm)
+ err := userProvider.GetUser(ctx, []interface{}{"A001"}, user)
+ if err != nil {
+ panic(err)
+ }
+
+ gxlog.CInfo(fmt.Sprintf("response result: %v\n", user))
+ initSignal()
+}
+
+func initSignal() {
+ signals := make(chan os.Signal, 1)
+ // It is not possible to block SIGKILL or syscall.SIGSTOP
+ signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP,
+ syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
+ for {
+ sig := <-signals
+ logger.Infof("get signal %s", sig.String())
+ switch sig {
+ case syscall.SIGHUP:
+ // reload()
+ default:
+ time.AfterFunc(time.Duration(survivalTimeout), func() {
+ logger.Warnf("app exit now by force...")
+ os.Exit(1)
+ })
+
+ // The program exits normally or timeout forcibly exits.
+ fmt.Println("app exit now...")
+ return
+ }
+ }
+}
+
+var userProvider = new(UserProvider)
+
+func init() {
+ config.SetConsumerService(userProvider)
+ hessian.RegisterPOJO(&User{})
+}
+
+type User struct {
+ Id string
+ Name string
+ Age int32
+ Time time.Time
+}
+
+type UserProvider struct {
+ GetUser func(ctx context.Context, req []interface{}, rsp *User) error
+}
+
+func (u *UserProvider) Reference() string {
+ return "UserProvider"
+}
+
+func (User) JavaClassName() string {
+ return "com.ikurento.user.User"
+}
diff --git a/router/tag/go-client/assembly/bin/load.sh b/router/tag/go-client/assembly/bin/load.sh
new file mode 100644
index 0000000..4435213
--- /dev/null
+++ b/router/tag/go-client/assembly/bin/load.sh
@@ -0,0 +1,203 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+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 CONF_ROUTER_FILE_PATH=${PROJECT_HOME}"TARGET_ROUTER_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/router/tag/go-client/assembly/common/app.properties b/router/tag/go-client/assembly/common/app.properties
new file mode 100644
index 0000000..3c6efe9
--- /dev/null
+++ b/router/tag/go-client/assembly/common/app.properties
@@ -0,0 +1,24 @@
+#
+# 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.
+
+
+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"
+export TARGET_ROUTER_CONF_FILE="conf/router_config.yml"
diff --git a/router/tag/go-client/assembly/common/build.sh b/router/tag/go-client/assembly/common/build.sh
new file mode 100644
index 0000000..c612dd4
--- /dev/null
+++ b/router/tag/go-client/assembly/common/build.sh
@@ -0,0 +1,89 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+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 GO111MODULE=on go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd -
+else
+ # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果),
+ # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试,
+ # -w基本没啥损失。-s的损失就有点大了。
+ cd ${BUILD_PACKAGE} && GOOS=$GOOS GOARCH=$GOARCH GO111MODULE=on 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
+
+# modify TARGET_ROUTER_CONF_FILE
+if [ ${platform} == "Darwin" ]; then
+ sed -i "" "s~TARGET_ROUTER_CONF_FILE~${TARGET_ROUTER_CONF_FILE}~g" ${BIN_DIR}/bin/*
+else
+ sed -i "s~TARGET_ROUTER_CONF_FILE~${TARGET_ROUTER_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/router/tag/go-client/assembly/linux/dev.sh b/router/tag/go-client/assembly/linux/dev.sh
new file mode 100644
index 0000000..eada737
--- /dev/null
+++ b/router/tag/go-client/assembly/linux/dev.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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/router/tag/go-client/assembly/linux/release.sh b/router/tag/go-client/assembly/linux/release.sh
new file mode 100644
index 0000000..cdd8405
--- /dev/null
+++ b/router/tag/go-client/assembly/linux/release.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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
\ No newline at end of file
diff --git a/router/tag/go-client/assembly/linux/test.sh b/router/tag/go-client/assembly/linux/test.sh
new file mode 100644
index 0000000..e618481
--- /dev/null
+++ b/router/tag/go-client/assembly/linux/test.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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
\ No newline at end of file
diff --git a/router/tag/go-client/assembly/mac/dev.sh b/router/tag/go-client/assembly/mac/dev.sh
new file mode 100644
index 0000000..c828476
--- /dev/null
+++ b/router/tag/go-client/assembly/mac/dev.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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/router/tag/go-client/assembly/mac/release.sh b/router/tag/go-client/assembly/mac/release.sh
new file mode 100644
index 0000000..91c2dfe
--- /dev/null
+++ b/router/tag/go-client/assembly/mac/release.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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/router/tag/go-client/assembly/mac/test.sh b/router/tag/go-client/assembly/mac/test.sh
new file mode 100644
index 0000000..a7853f5
--- /dev/null
+++ b/router/tag/go-client/assembly/mac/test.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+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/router/tag/go-client/assembly/windows/dev.sh b/router/tag/go-client/assembly/windows/dev.sh
new file mode 100644
index 0000000..6487b30
--- /dev/null
+++ b/router/tag/go-client/assembly/windows/dev.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=windows
+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/router/tag/go-client/assembly/windows/release.sh b/router/tag/go-client/assembly/windows/release.sh
new file mode 100644
index 0000000..21af573
--- /dev/null
+++ b/router/tag/go-client/assembly/windows/release.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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/router/tag/go-client/assembly/windows/test.sh b/router/tag/go-client/assembly/windows/test.sh
new file mode 100644
index 0000000..2104da8
--- /dev/null
+++ b/router/tag/go-client/assembly/windows/test.sh
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+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/router/tag/go-client/profiles/dev/client.yml b/router/tag/go-client/profiles/dev/client.yml
new file mode 100644
index 0000000..390c5ca
--- /dev/null
+++ b/router/tag/go-client/profiles/dev/client.yml
@@ -0,0 +1,62 @@
+# dubbo client yaml configure file
+
+
+check: true
+# client
+request_timeout : "3s"
+# connect timeout
+connect_timeout : "3s"
+
+config_center:
+ protocol: "zookeeper"
+ address: "127.0.0.1:2181"
+
+# application config
+application:
+ organization : "ikurento.com"
+ name : "BDTService"
+ module : "dubbogo user-info client"
+ version : "0.0.1"
+ owner : "ZX"
+ environment : "dev"
+
+registries :
+ "hangzhouzk":
+ protocol: "zookeeper"
+ timeout : "3s"
+ address: "127.0.0.1:2181"
+ username: ""
+ password: ""
+
+references:
+ "UserProvider":
+ # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ registry: "hangzhouzk"
+ protocol : "dubbo"
+ interface : "com.ikurento.user.UserProvider"
+ cluster: "failover"
+ methods :
+ - name: "GetUser"
+ retries: 3
+
+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/router/tag/go-client/profiles/dev/log.yml b/router/tag/go-client/profiles/dev/log.yml
new file mode 100644
index 0000000..3ed242d
--- /dev/null
+++ b/router/tag/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/router/tag/go-client/profiles/dev/router_config.yml b/router/tag/go-client/profiles/dev/router_config.yml
new file mode 100644
index 0000000..2467ebe
--- /dev/null
+++ b/router/tag/go-client/profiles/dev/router_config.yml
@@ -0,0 +1,14 @@
+# dubbo router yaml configure file
+routerRules:
+ - scope: application
+ force: true
+ runtime: false
+ enabled: true
+ valid: true
+ priority: 1
+ key: demo-provider
+ tags:
+ - name: beijing
+ addresses: [192.168.1.1, 192.168.1.2]
+ - name: shenzhen
+ addresses: [192.168.1.3, 192.168.1.4]
\ No newline at end of file
diff --git a/router/tag/go-server/app/server.go b/router/tag/go-server/app/server.go
new file mode 100644
index 0000000..18c2736
--- /dev/null
+++ b/router/tag/go-server/app/server.go
@@ -0,0 +1,78 @@
+/*
+ * 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 (
+ "os"
+ "os/signal"
+ "syscall"
+ "time"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ _ "github.com/apache/dubbo-go/cluster/cluster_impl"
+ _ "github.com/apache/dubbo-go/cluster/loadbalance"
+ _ "github.com/apache/dubbo-go/cluster/router/tag"
+ "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/config"
+ _ "github.com/apache/dubbo-go/config_center/zookeeper"
+ _ "github.com/apache/dubbo-go/filter/filter_impl"
+ _ "github.com/apache/dubbo-go/protocol/dubbo"
+ _ "github.com/apache/dubbo-go/registry/protocol"
+ _ "github.com/apache/dubbo-go/registry/zookeeper"
+)
+
+var (
+ survivalTimeout = int(3e9)
+)
+
+// they are necessary:
+// export CONF_PROVIDER_FILE_PATH="xxx"
+// export APP_LOG_CONF_FILE="xxx"
+func main() {
+ hessian.RegisterPOJO(&User{})
+ config.Load()
+
+ initSignal()
+}
+
+func initSignal() {
+ signals := make(chan os.Signal, 1)
+ // It is not possible to block SIGKILL or syscall.SIGSTOP
+ signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
+ for {
+ sig := <-signals
+ logger.Infof("get signal %s", sig.String())
+ switch sig {
+ case syscall.SIGHUP:
+ // reload()
+ default:
+ time.AfterFunc(time.Duration(survivalTimeout), func() {
+ logger.Warnf("app exit now by force...")
+ os.Exit(1)
+ })
+
+ // The program exits normally or timeout forcibly exits.
+ logger.Info("provider app exit now...")
+ return
+ }
+ }
+}
diff --git a/router/tag/go-server/app/user.go b/router/tag/go-server/app/user.go
new file mode 100644
index 0000000..0c2512c
--- /dev/null
+++ b/router/tag/go-server/app/user.go
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package main
+
+import (
+ "context"
+ "time"
+)
+
+import (
+ hessian "github.com/apache/dubbo-go-hessian2"
+ "github.com/apache/dubbo-go/config"
+ gxlog "github.com/dubbogo/gost/log"
+)
+
+func init() {
+ config.SetProviderService(new(UserProvider))
+ // ------for hessian2------
+ hessian.RegisterPOJO(&User{})
+}
+
+type User struct {
+ Id string
+ Name string
+ Age int32
+ Time time.Time
+}
+
+type UserProvider struct {
+}
+
+func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) {
+ gxlog.CInfo("req:%#v", req)
+ rsp := User{"A001", "Alex Stocks", 18, time.Now()}
+ gxlog.CInfo("rsp:%#v", rsp)
+ return &rsp, nil
+}
+
+func (u *UserProvider) Reference() string {
+ return "UserProvider"
+}
+
+func (u User) JavaClassName() string {
+ return "com.ikurento.user.User"
+}
diff --git a/router/tag/go-server/app/version.go b/router/tag/go-server/app/version.go
new file mode 100644
index 0000000..ae51f45
--- /dev/null
+++ b/router/tag/go-server/app/version.go
@@ -0,0 +1,22 @@
+/*
+ * 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
+
+var (
+ Version = "2.7.5"
+)
diff --git a/router/tag/go-server/assembly/bin/load.sh b/router/tag/go-server/assembly/bin/load.sh
new file mode 100644
index 0000000..90077c2
--- /dev/null
+++ b/router/tag/go-server/assembly/bin/load.sh
@@ -0,0 +1,151 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+APP_NAME="APPLICATION_NAME"
+APP_ARGS=""
+
+
+PROJECT_HOME=""
+OS_NAME=`uname`
+if [[ ${OS_NAME} != "Windows" ]]; then
+ PROJECT_HOME=`pwd`
+ PROJECT_HOME=${PROJECT_HOME}"/"
+fi
+
+export CONF_PROVIDER_FILE_PATH=${PROJECT_HOME}"TARGET_CONF_FILE"
+export APP_LOG_CONF_FILE=${PROJECT_HOME}"TARGET_LOG_CONF_FILE"
+
+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 server.yml!"
+ else
+ export CONF_PROVIDER_FILE_PATH=${CONF_PROVIDER_FILE_PATH//\.yml/\_$arg\.yml}
+ fi
+ if [ ! -f "${CONF_PROVIDER_FILE_PATH}" ];then
+ echo $CONF_PROVIDER_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
+}
+
+opt=$1
+case C"$opt" in
+ Cstart)
+ start $2
+ ;;
+ Cstop)
+ stop
+ ;;
+ Cterm)
+ term
+ ;;
+ Crestart)
+ term
+ start $2
+ ;;
+ Clist)
+ list
+ ;;
+ C*)
+ usage
+ ;;
+esac
+
diff --git a/router/tag/go-server/assembly/common/app.properties b/router/tag/go-server/assembly/common/app.properties
new file mode 100644
index 0000000..1f0827e
--- /dev/null
+++ b/router/tag/go-server/assembly/common/app.properties
@@ -0,0 +1,23 @@
+#
+# 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.
+
+
+TARGET_EXEC_NAME="user_info_server"
+# BUILD_PACKAGE="dubbogo-examples/user-info/server/app"
+BUILD_PACKAGE="app"
+
+TARGET_CONF_FILE="conf/server.yml"
+TARGET_LOG_CONF_FILE="conf/log.yml"
diff --git a/router/tag/go-server/assembly/common/build.sh b/router/tag/go-server/assembly/common/build.sh
new file mode 100644
index 0000000..d90d026
--- /dev/null
+++ b/router/tag/go-server/assembly/common/build.sh
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+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 = "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} && GO111MODULE=on go build -gcflags "-N -l" -x -v -i -o ${TARGET_NAME} && cd -
+else
+ # -s去掉符号表(然后panic时候的stack trace就没有任何文件名/行号信息了,这个等价于普通C/C++程序被strip的效果),
+ # -w去掉DWARF调试信息,得到的程序就不能用gdb调试了。-s和-w也可以分开使用,一般来说如果不打算用gdb调试,
+ # -w基本没啥损失。-s的损失就有点大了。
+ cd ${BUILD_PACKAGE} && GO111MODULE=on 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}
+# modify APPLICATION_NAME
+# OS=`uname`
+# if [[ $OS=="Darwin" ]]; then
+if [ "$(uname)" == "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 [ "$(uname)" == "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 [ "$(uname)" == "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/router/tag/go-server/assembly/linux/dev.sh b/router/tag/go-server/assembly/linux/dev.sh
new file mode 100644
index 0000000..d830ac9
--- /dev/null
+++ b/router/tag/go-server/assembly/linux/dev.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=linux
+export GOARCH=amd64
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/linux/release.sh b/router/tag/go-server/assembly/linux/release.sh
new file mode 100644
index 0000000..9930380
--- /dev/null
+++ b/router/tag/go-server/assembly/linux/release.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=linux
+export GOARCH=amd64
+
+PROFILE=release
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/linux/test.sh b/router/tag/go-server/assembly/linux/test.sh
new file mode 100644
index 0000000..87144bb
--- /dev/null
+++ b/router/tag/go-server/assembly/linux/test.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=linux
+export GOARCH=amd64
+
+PROFILE=test
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/mac/dev.sh b/router/tag/go-server/assembly/mac/dev.sh
new file mode 100644
index 0000000..3a7659b
--- /dev/null
+++ b/router/tag/go-server/assembly/mac/dev.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=darwin
+export GOARCH=amd64
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/mac/release.sh b/router/tag/go-server/assembly/mac/release.sh
new file mode 100644
index 0000000..1c4bce4
--- /dev/null
+++ b/router/tag/go-server/assembly/mac/release.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=darwin
+export GOARCH=amd64
+
+PROFILE=release
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/mac/test.sh b/router/tag/go-server/assembly/mac/test.sh
new file mode 100644
index 0000000..69206e3
--- /dev/null
+++ b/router/tag/go-server/assembly/mac/test.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+set -e
+
+export GOOS=darwin
+export GOARCH=amd64
+
+PROFILE=test
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
+
diff --git a/router/tag/go-server/assembly/windows/dev.sh b/router/tag/go-server/assembly/windows/dev.sh
new file mode 100644
index 0000000..011fb41
--- /dev/null
+++ b/router/tag/go-server/assembly/windows/dev.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=windows
+export GOARCH=amd64
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/windows/release.sh b/router/tag/go-server/assembly/windows/release.sh
new file mode 100644
index 0000000..679a26a
--- /dev/null
+++ b/router/tag/go-server/assembly/windows/release.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=windows
+export GOARCH=amd64
+
+PROFILE=release
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/assembly/windows/test.sh b/router/tag/go-server/assembly/windows/test.sh
new file mode 100644
index 0000000..4a36de0
--- /dev/null
+++ b/router/tag/go-server/assembly/windows/test.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+
+set -e
+
+export GOOS=windows
+export GOARCH=amd64
+
+PROFILE=test
+
+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
+. ${PROJECT_HOME}/assembly/common/build.sh
+fi
diff --git a/router/tag/go-server/profiles/dev/log.yml b/router/tag/go-server/profiles/dev/log.yml
new file mode 100644
index 0000000..3ed242d
--- /dev/null
+++ b/router/tag/go-server/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/router/tag/go-server/profiles/dev/server.yml b/router/tag/go-server/profiles/dev/server.yml
new file mode 100644
index 0000000..06797d0
--- /dev/null
+++ b/router/tag/go-server/profiles/dev/server.yml
@@ -0,0 +1,95 @@
+# dubbo server yaml configure file
+
+
+# application config
+application:
+ organization : "ikurento.com"
+ name : "BDTService"
+ module : "dubbogo user-info server"
+ version : "0.0.1"
+ owner : "ZX"
+ environment : "dev"
+
+registries :
+ "hangzhouzk":
+ # 对应java配置中address属性的zookeeper <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+ protocol: "zookeeper"
+ timeout : "3s"
+ address: "127.0.0.1:2181"
+ username: ""
+ password: ""
+ "shanghaizk":
+ protocol: "zookeeper"
+ timeout : "3s"
+ address: "127.0.0.1:2181"
+ username: ""
+ password: ""
+
+
+services:
+ "UserProvider":
+ # 可以指定多个registry,使用逗号隔开;不指定默认向所有注册中心注册
+ registry: "hangzhouzk"
+ protocol : "dubbo"
+ # 相当于dubbo.xml中的interface
+ interface : "com.ikurento.user.UserProvider"
+ loadbalance: "random"
+ warmup: "100"
+ tag: "beijing"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 1
+ loadbalance: "random"
+ "UserProvider1":
+ registry: "hangzhouzk"
+ protocol: "dubbo"
+ tag: "shanghai"
+ version: "2.0"
+ interface: "com.ikurento.user.UserProvider"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 1
+ loadbalance: "random"
+ "UserProvider2":
+ registry: "hangzhouzk"
+ protocol: "dubbo"
+ tag: "shenzhen"
+ version: "2.0"
+ group: "as"
+ interface: "com.ikurento.user.UserProvider"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "GetUser"
+ retries: 1
+ loadbalance: "random"
+
+protocols:
+ "dubbo":
+ name: "dubbo"
+ # ip : "127.0.0.1"
+ port: 20000
+
+
+protocol_conf:
+ dubbo:
+ session_number: 700
+ session_timeout: "180s"
+ 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: 1024
+ session_name: "server"
\ No newline at end of file
diff --git a/router/tag/java-client/build.sh b/router/tag/java-client/build.sh
new file mode 100644
index 0000000..c869acf
--- /dev/null
+++ b/router/tag/java-client/build.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+# rm src/main/resources/META-INF/spring/dubbo.consumer.xml
+# cp src/main/resources/META-INF/spring/dubbo-protocol.consumer.xml src/main/resources/META-INF/spring/dubbo.consumer.xml
+# cp src/main/resources/META-INF/spring/jsonrpc-protocol.consumer.xml src/main/resources/META-INF/spring/dubbo.consumer.xml
+mvn clean package -Dmaven.test.skip
diff --git a/router/tag/java-client/pom.xml b/router/tag/java-client/pom.xml
new file mode 100644
index 0000000..ce2d151
--- /dev/null
+++ b/router/tag/java-client/pom.xml
@@ -0,0 +1,211 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.ikurento</groupId>
+ <artifactId>user-info-client</artifactId>
+ <packaging>jar</packaging>
+ <version>0.2.0</version>
+ <description>The demo consumer module of dubbo project</description>
+
+ <properties>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <dubbo.version>2.7.3</dubbo.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <junit.version>4.12</junit.version>
+ <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
+ <jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+ <image.name>${artifactId}:${dubbo.version}</image.name>
+ <java-image.name>openjdk:8</java-image.name>
+ <dubbo.port>20880</dubbo.port>
+ <zookeeper.port>2181</zookeeper.port>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-apollo</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dubbo-integration-test</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-maven-address-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>local-address</goal>
+ </goals>
+ <configuration>
+ <localAddress>dubbo-local-address</localAddress>
+ </configuration>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>${jib-maven-plugin.version}</version>
+ <configuration>
+ <from>
+ <image>${java-image.name}</image>
+ </from>
+ <to>
+ <image>${image.name}</image>
+ </to>
+ <container>
+ <mainClass>${main-class}</mainClass>
+ <ports>
+ <port>${dubbo.port}</port>
+ <port>${zookeeper.port}</port>
+ </ports>
+ <environment>
+ <DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
+ </environment>
+ <jvmFlags>
+ <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+ </jvmFlags>
+ </container>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>dockerBuild</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>${docker-maven-plugin.version}</version>
+ <configuration>
+ <images>
+ <image>
+ <name>${image.name}</name>
+ <run>
+ <ports>
+ <port>${dubbo.port}:${dubbo.port}</port>
+ <port>${zookeeper.port}:${zookeeper.port}</port>
+ </ports>
+ <wait>
+ <log>dubbo service started</log>
+ </wait>
+ </run>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${maven-failsafe-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <systemPropertyVariables>
+ <zookeeper.address>${dubbo-local-address}</zookeeper.address>
+ </systemPropertyVariables>
+ <includes>
+ <include>**/*IT.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/router/tag/java-client/src/main/assembly/assembly.xml b/router/tag/java-client/src/main/assembly/assembly.xml
new file mode 100644
index 0000000..84f5499
--- /dev/null
+++ b/router/tag/java-client/src/main/assembly/assembly.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>dubbo.properties</include>
+ <include>log4j.*</include>
+ </includes>
+ <outputDirectory>conf</outputDirectory>
+ <fileMode>0644</fileMode>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>lib</outputDirectory>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
diff --git a/router/tag/java-client/src/main/java/com/ikurento/user/Consumer.java b/router/tag/java-client/src/main/java/com/ikurento/user/Consumer.java
new file mode 100644
index 0000000..6abfb93
--- /dev/null
+++ b/router/tag/java-client/src/main/java/com/ikurento/user/Consumer.java
@@ -0,0 +1,61 @@
+/*
+ * 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 java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+public class Consumer {
+ // Define a private variable (Required in Spring)
+ private UserProvider userProvider;
+
+ // Spring DI (Required in Spring)
+ public void setUserProvider(UserProvider u) {
+ this.userProvider = u;
+ }
+
+ public static void main(String[] args) throws Exception {
+// new EmbeddedZooKeeper(2181, false).start();
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.consumer.xml","META-INF/spring/service.xml");
+ context.start();
+ context.getBean(Consumer.class).start();
+ }
+
+ // Start the entry function for consumer (Specified in the configuration file)
+ public void start() {
+ System.out.println("\n\ntest");
+ testGetUser();
+ }
+
+ private void testGetUser() {
+ try {
+ User user1 = userProvider.GetUser("A003");
+ System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] " +
+ " UserInfo, Id:" + user1.getId() + ", name:" + user1.getName()
+ + ", age:" + user1.getAge() + ", time:" + user1.getTime().toString());
+
+ } catch (Exception e) {
+ System.out.println("*************exception***********");
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/router/tag/java-client/src/main/java/com/ikurento/user/EmbeddedZooKeeper.java b/router/tag/java-client/src/main/java/com/ikurento/user/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..fb99a0d
--- /dev/null
+++ b/router/tag/java-client/src/main/java/com/ikurento/user/EmbeddedZooKeeper.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * 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.
+ */
+package com.ikurento.user;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+import org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ * <p>
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ * <p>
+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+ /**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+ /**
+ * ZooKeeper client port. This will be determined dynamically upon startup.
+ */
+ private final int clientPort;
+
+ /**
+ * Whether to auto-start. Default is true.
+ */
+ private boolean autoStartup = true;
+
+ /**
+ * Lifecycle phase. Default is 0.
+ */
+ private int phase = 0;
+
+ /**
+ * Thread for running the ZooKeeper server.
+ */
+ private volatile Thread zkServerThread;
+
+ /**
+ * ZooKeeper server.
+ */
+ private volatile ZooKeeperServerMain zkServer;
+
+ /**
+ * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
+ */
+ private ErrorHandler errorHandler;
+
+ private boolean daemon = true;
+
+ /**
+ * Construct an EmbeddedZooKeeper with a random port.
+ */
+ public EmbeddedZooKeeper() {
+ clientPort = SocketUtils.findAvailableTcpPort();
+ }
+
+ /**
+ * Construct an EmbeddedZooKeeper with the provided port.
+ *
+ * @param clientPort port for ZooKeeper server to bind to
+ */
+ public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+ this.clientPort = clientPort;
+ this.daemon = daemon;
+ }
+
+ /**
+ * Returns the port that clients should use to connect to this embedded server.
+ *
+ * @return dynamically determined client port
+ */
+ public int getClientPort() {
+ return this.clientPort;
+ }
+
+ /**
+ * Specify whether to start automatically. Default is true.
+ *
+ * @param autoStartup whether to start automatically
+ */
+ public void setAutoStartup(boolean autoStartup) {
+ this.autoStartup = autoStartup;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isAutoStartup() {
+ return this.autoStartup;
+ }
+
+ /**
+ * Specify the lifecycle phase for the embedded server.
+ *
+ * @param phase the lifecycle phase
+ */
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getPhase() {
+ return this.phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRunning() {
+ return (zkServerThread != null);
+ }
+
+ /**
+ * Start the ZooKeeper server in a background thread.
+ * <p>
+ * Register an error handler via {@link #setErrorHandler} in order to handle
+ * any exceptions thrown during startup or execution.
+ */
+ @Override
+ public synchronized void start() {
+ if (zkServerThread == null) {
+ zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
+ zkServerThread.setDaemon(daemon);
+ zkServerThread.start();
+ }
+ }
+
+ /**
+ * Shutdown the ZooKeeper server.
+ */
+ @Override
+ public synchronized void stop() {
+ if (zkServerThread != null) {
+ // The shutdown method is protected...thus this hack to invoke it.
+ // This will log an exception on shutdown; see
+ // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
+ try {
+ Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+ shutdown.setAccessible(true);
+ shutdown.invoke(zkServer);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // It is expected that the thread will exit after
+ // the server is shutdown; this will block until
+ // the shutdown is complete.
+ try {
+ zkServerThread.join(5000);
+ zkServerThread = null;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
+ // abandoning zk thread
+ zkServerThread = null;
+ }
+ }
+ }
+
+ /**
+ * Stop the server if running and invoke the callback when complete.
+ */
+ @Override
+ public void stop(Runnable callback) {
+ stop();
+ callback.run();
+ }
+
+ /**
+ * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
+ * is provided, only error-level logging will occur.
+ *
+ * @param errorHandler the {@link ErrorHandler} to be invoked
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Runnable implementation that starts the ZooKeeper server.
+ */
+ private class ServerRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ try {
+ Properties properties = new Properties();
+ File file = new File(System.getProperty("java.io.tmpdir")
+ + File.separator + UUID.randomUUID());
+ file.deleteOnExit();
+ properties.setProperty("dataDir", file.getAbsolutePath());
+ properties.setProperty("clientPort", String.valueOf(clientPort));
+
+ QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+ quorumPeerConfig.parseProperties(properties);
+
+ zkServer = new ZooKeeperServerMain();
+ ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumPeerConfig);
+
+ zkServer.runFromConfig(configuration);
+ } catch (Exception e) {
+ if (errorHandler != null) {
+ errorHandler.handleError(e);
+ } else {
+ logger.error("Exception running embedded ZooKeeper", e);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/router/tag/java-client/src/main/java/com/ikurento/user/User.java b/router/tag/java-client/src/main/java/com/ikurento/user/User.java
new file mode 100644
index 0000000..1526244
--- /dev/null
+++ b/router/tag/java-client/src/main/java/com/ikurento/user/User.java
@@ -0,0 +1,76 @@
+/*
+ * 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 java.util.Date;
+
+public class User {
+
+ private String id;
+
+ private String name;
+
+ private int age;
+
+ private Date time = new Date();
+
+
+ public User() {
+ }
+
+
+ public User(String id, String name, int age) {
+ this.id = id;
+ this.name = name;
+ this.age = age;
+ }
+
+ 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;
+ }
+
+
+}
diff --git a/router/tag/java-client/src/main/java/com/ikurento/user/UserProvider.java b/router/tag/java-client/src/main/java/com/ikurento/user/UserProvider.java
new file mode 100644
index 0000000..f42452d
--- /dev/null
+++ b/router/tag/java-client/src/main/java/com/ikurento/user/UserProvider.java
@@ -0,0 +1,18 @@
+/*
+ * 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.
+ */
+package com.ikurento.user;
+
+public interface UserProvider {
+ User GetUser(String userId);
+}
diff --git a/router/tag/java-client/src/main/java/com/ikurento/user/ZKTools.java b/router/tag/java-client/src/main/java/com/ikurento/user/ZKTools.java
new file mode 100644
index 0000000..65059ec
--- /dev/null
+++ b/router/tag/java-client/src/main/java/com/ikurento/user/ZKTools.java
@@ -0,0 +1,88 @@
+/*
+ * 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.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+
+public class ZKTools {
+ private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
+ private static CuratorFramework client;
+
+ public static void main(String[] args) throws Exception {
+ generateDubboProperties();
+ }
+
+ public static void generateDubboProperties() {
+ client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
+ new ExponentialBackoffRetry(1000, 3));
+ client.start();
+
+ generateDubboPropertiesForGlobal();
+ generateDubboPropertiesForConsumer();
+ }
+
+ public static void generateDubboPropertiesForGlobal() {
+ String str = "dubbo.registry.address=zookeeper://" + zookeeperHost + ":2181\n" +
+// "dubbo.metadata-report.address=zookeeper://" + zookeeperHost + ":2181\n" +
+ "dubbo.protocol.port=-1\n" +
+// "dubbo.registry.simplified=true\n"+
+ "";
+
+ System.out.println(str);
+
+ try {
+ String path = "/dubbo/config/dubbo/dubbo.properties";
+ if (client.checkExists().forPath(path) == null) {
+ client.create().creatingParentsIfNeeded().forPath(path);
+ }
+ setData(path, str);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void generateDubboPropertiesForConsumer() {
+ String str = "dubbo.consumer.timeout=6666\n" +
+ "dubbo.reference.com.ikurento.user.UserProvider.cluster=failback";
+
+ System.out.println(str);
+
+ try {
+ String path = "/dubbo/config/user-info-client/dubbo.properties";
+ if (client.checkExists().forPath(path) == null) {
+ client.create().creatingParentsIfNeeded().forPath(path);
+ }
+ setData(path, str);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void createNode(String path) throws Exception {
+ client.create().forPath(path);
+ }
+
+ private static void deleteNode(String path) throws Exception {
+ client.delete().forPath(path);
+ }
+
+ private static void setData(String path, String data) throws Exception {
+ client.setData().forPath(path, data.getBytes());
+ }
+}
diff --git a/router/tag/java-client/src/main/resources/META-INF/spring/dubbo.consumer.xml b/router/tag/java-client/src/main/resources/META-INF/spring/dubbo.consumer.xml
new file mode 100644
index 0000000..75e6fec
--- /dev/null
+++ b/router/tag/java-client/src/main/resources/META-INF/spring/dubbo.consumer.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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-client" />
+ <!-- 连接到哪个本地注册中心 -->
+ <dubbo:registry id="ikurento" address="zookeeper://127.0.0.1:2181" />
+ <!-- dubbo.registry.address from dubbo.properties -->
+ <!-- dubbo:registry address="${dubbo.registry.address}" / -->
+
+ <!-- 用dubbo协议在20880端口暴露服务 -->
+ <dubbo:protocol id="dubbo" name="dubbo" />
+ <dubbo:protocol id="jsonrpc" name="jsonrpc" />
+
+ <!-- 声明需要使用的服务接口 -->
+ <dubbo:reference registry="ikurento" check="false" id="userProvider" protocol="dubbo" interface="com.ikurento.user.UserProvider">
+ <!--<dubbo:parameter key="heartbeat" value="10000"/ -->
+ </dubbo:reference>
+</beans>
diff --git a/router/tag/java-client/src/main/resources/META-INF/spring/service.xml b/router/tag/java-client/src/main/resources/META-INF/spring/service.xml
new file mode 100644
index 0000000..e4f5fda
--- /dev/null
+++ b/router/tag/java-client/src/main/resources/META-INF/spring/service.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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:context="http://www.springframework.org/schema/context"
+ 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">
+
+ <bean class="com.ikurento.user.Consumer" init-method="start">
+ <!-- 声明这个类 要使用的服务名-->
+ <property name="userProvider" ref="userProvider" />
+ </bean>
+
+</beans>
diff --git a/router/tag/java-client/src/main/resources/log4j.properties b/router/tag/java-client/src/main/resources/log4j.properties
new file mode 100644
index 0000000..06bcb34
--- /dev/null
+++ b/router/tag/java-client/src/main/resources/log4j.properties
@@ -0,0 +1,19 @@
+## 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/router/tag/java-server/build.sh b/router/tag/java-server/build.sh
new file mode 100644
index 0000000..7b5755b
--- /dev/null
+++ b/router/tag/java-server/build.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+# mvn dependency:sources
+mvn clean package -Dmaven.test.skip
+# mvn -X clean compile package -DskipTests=true
diff --git a/router/tag/java-server/pom.xml b/router/tag/java-server/pom.xml
new file mode 100644
index 0000000..310c617
--- /dev/null
+++ b/router/tag/java-server/pom.xml
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+
+<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>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <dubbo.version>2.7.3</dubbo.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <junit.version>4.12</junit.version>
+ <docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
+ <jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
+ <image.name>${artifactId}:${dubbo.version}</image.name>
+ <java-image.name>openjdk:8</java-image.name>
+ <dubbo.port>20880</dubbo.port>
+ <zookeeper.port>2181</zookeeper.port>
+ <main-class>org.apache.dubbo.samples.configcenter.BasicProvider</main-class>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dubbo-integration-test</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-maven-address-plugin</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>local-address</goal>
+ </goals>
+ <configuration>
+ <localAddress>dubbo-local-address</localAddress>
+ </configuration>
+ <phase>initialize</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>com.google.cloud.tools</groupId>
+ <artifactId>jib-maven-plugin</artifactId>
+ <version>${jib-maven-plugin.version}</version>
+ <configuration>
+ <from>
+ <image>${java-image.name}</image>
+ </from>
+ <to>
+ <image>${image.name}</image>
+ </to>
+ <container>
+ <mainClass>${main-class}</mainClass>
+ <ports>
+ <port>${dubbo.port}</port>
+ <port>${zookeeper.port}</port>
+ </ports>
+ <environment>
+ <DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
+ </environment>
+ <jvmFlags>
+ <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
+ </jvmFlags>
+ </container>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>dockerBuild</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>io.fabric8</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>${docker-maven-plugin.version}</version>
+ <configuration>
+ <images>
+ <image>
+ <name>${image.name}</name>
+ <run>
+ <ports>
+ <port>${dubbo.port}:${dubbo.port}</port>
+ <port>${zookeeper.port}:${zookeeper.port}</port>
+ </ports>
+ <wait>
+ <log>dubbo service started</log>
+ </wait>
+ </run>
+ </image>
+ </images>
+ </configuration>
+ <executions>
+ <execution>
+ <id>start</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${maven-failsafe-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <systemPropertyVariables>
+ <zookeeper.address>${dubbo-local-address}</zookeeper.address>
+ </systemPropertyVariables>
+ <includes>
+ <include>**/*IT.java</include>
+ </includes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
+
diff --git a/router/tag/java-server/script/debug.sh b/router/tag/java-server/script/debug.sh
new file mode 100644
index 0000000..851957a
--- /dev/null
+++ b/router/tag/java-server/script/debug.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+#
+# 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.
+
+
+# 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/router/tag/java-server/src/main/assembly/assembly.xml b/router/tag/java-server/src/main/assembly/assembly.xml
new file mode 100644
index 0000000..ce8e7e7
--- /dev/null
+++ b/router/tag/java-server/src/main/assembly/assembly.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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/resources</directory>
+ <includes>
+ <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/router/tag/java-server/src/main/java/com/ikurento/user/EmbeddedZooKeeper.java b/router/tag/java-server/src/main/java/com/ikurento/user/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..fb99a0d
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/EmbeddedZooKeeper.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * 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.
+ */
+package com.ikurento.user;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+import org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ * <p>
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ * <p>
+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+ /**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+ /**
+ * ZooKeeper client port. This will be determined dynamically upon startup.
+ */
+ private final int clientPort;
+
+ /**
+ * Whether to auto-start. Default is true.
+ */
+ private boolean autoStartup = true;
+
+ /**
+ * Lifecycle phase. Default is 0.
+ */
+ private int phase = 0;
+
+ /**
+ * Thread for running the ZooKeeper server.
+ */
+ private volatile Thread zkServerThread;
+
+ /**
+ * ZooKeeper server.
+ */
+ private volatile ZooKeeperServerMain zkServer;
+
+ /**
+ * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
+ */
+ private ErrorHandler errorHandler;
+
+ private boolean daemon = true;
+
+ /**
+ * Construct an EmbeddedZooKeeper with a random port.
+ */
+ public EmbeddedZooKeeper() {
+ clientPort = SocketUtils.findAvailableTcpPort();
+ }
+
+ /**
+ * Construct an EmbeddedZooKeeper with the provided port.
+ *
+ * @param clientPort port for ZooKeeper server to bind to
+ */
+ public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+ this.clientPort = clientPort;
+ this.daemon = daemon;
+ }
+
+ /**
+ * Returns the port that clients should use to connect to this embedded server.
+ *
+ * @return dynamically determined client port
+ */
+ public int getClientPort() {
+ return this.clientPort;
+ }
+
+ /**
+ * Specify whether to start automatically. Default is true.
+ *
+ * @param autoStartup whether to start automatically
+ */
+ public void setAutoStartup(boolean autoStartup) {
+ this.autoStartup = autoStartup;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isAutoStartup() {
+ return this.autoStartup;
+ }
+
+ /**
+ * Specify the lifecycle phase for the embedded server.
+ *
+ * @param phase the lifecycle phase
+ */
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getPhase() {
+ return this.phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRunning() {
+ return (zkServerThread != null);
+ }
+
+ /**
+ * Start the ZooKeeper server in a background thread.
+ * <p>
+ * Register an error handler via {@link #setErrorHandler} in order to handle
+ * any exceptions thrown during startup or execution.
+ */
+ @Override
+ public synchronized void start() {
+ if (zkServerThread == null) {
+ zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
+ zkServerThread.setDaemon(daemon);
+ zkServerThread.start();
+ }
+ }
+
+ /**
+ * Shutdown the ZooKeeper server.
+ */
+ @Override
+ public synchronized void stop() {
+ if (zkServerThread != null) {
+ // The shutdown method is protected...thus this hack to invoke it.
+ // This will log an exception on shutdown; see
+ // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
+ try {
+ Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+ shutdown.setAccessible(true);
+ shutdown.invoke(zkServer);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // It is expected that the thread will exit after
+ // the server is shutdown; this will block until
+ // the shutdown is complete.
+ try {
+ zkServerThread.join(5000);
+ zkServerThread = null;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
+ // abandoning zk thread
+ zkServerThread = null;
+ }
+ }
+ }
+
+ /**
+ * Stop the server if running and invoke the callback when complete.
+ */
+ @Override
+ public void stop(Runnable callback) {
+ stop();
+ callback.run();
+ }
+
+ /**
+ * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
+ * is provided, only error-level logging will occur.
+ *
+ * @param errorHandler the {@link ErrorHandler} to be invoked
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Runnable implementation that starts the ZooKeeper server.
+ */
+ private class ServerRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ try {
+ Properties properties = new Properties();
+ File file = new File(System.getProperty("java.io.tmpdir")
+ + File.separator + UUID.randomUUID());
+ file.deleteOnExit();
+ properties.setProperty("dataDir", file.getAbsolutePath());
+ properties.setProperty("clientPort", String.valueOf(clientPort));
+
+ QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+ quorumPeerConfig.parseProperties(properties);
+
+ zkServer = new ZooKeeperServerMain();
+ ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumPeerConfig);
+
+ zkServer.runFromConfig(configuration);
+ } catch (Exception e) {
+ if (errorHandler != null) {
+ errorHandler.handleError(e);
+ } else {
+ logger.error("Exception running embedded ZooKeeper", e);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/router/tag/java-server/src/main/java/com/ikurento/user/Provider.java b/router/tag/java-server/src/main/java/com/ikurento/user/Provider.java
new file mode 100644
index 0000000..12845fb
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/Provider.java
@@ -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 com.ikurento.user;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+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 {
+ new EmbeddedZooKeeper(2181, false).start();
+
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.provider.xml");
+ context.registerShutdownHook();
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+}
diff --git a/router/tag/java-server/src/main/java/com/ikurento/user/Provider2.java b/router/tag/java-server/src/main/java/com/ikurento/user/Provider2.java
new file mode 100644
index 0000000..1c0a92c
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/Provider2.java
@@ -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 com.ikurento.user;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class Provider2 {
+
+ /**
+ * 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 {
+ new EmbeddedZooKeeper(2181, false).start();
+
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.provider2.xml");
+ context.registerShutdownHook();
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+}
diff --git a/router/tag/java-server/src/main/java/com/ikurento/user/User.java b/router/tag/java-server/src/main/java/com/ikurento/user/User.java
new file mode 100644
index 0000000..ac046bd
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/User.java
@@ -0,0 +1,86 @@
+/*
+ * 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 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();
+
+ 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) {
+ this.id = id;
+ this.name = name;
+ this.age = age;
+ this.time = time;
+ }
+
+ 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 String toString() {
+ return "User{id:" + id + ", name:" + name + ", age:" + age + ", time:" + time +"}";
+ }
+}
diff --git a/router/tag/java-server/src/main/java/com/ikurento/user/UserProvider.java b/router/tag/java-server/src/main/java/com/ikurento/user/UserProvider.java
new file mode 100644
index 0000000..831588d
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/UserProvider.java
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+public interface UserProvider {
+
+ User GetUser(String userId); // the first alpha is Upper case to compatible with golang.
+
+}
diff --git a/router/tag/java-server/src/main/java/com/ikurento/user/ZKTools.java b/router/tag/java-server/src/main/java/com/ikurento/user/ZKTools.java
new file mode 100644
index 0000000..6ed90de
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/ZKTools.java
@@ -0,0 +1,89 @@
+/*
+ * 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.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+
+public class ZKTools {
+ private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
+ private static CuratorFramework client;
+
+ public static void main(String[] args) throws Exception {
+ generateDubboProperties();
+ }
+
+ public static void generateDubboProperties() {
+ client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
+ new ExponentialBackoffRetry(1000, 3));
+ client.start();
+
+ generateDubboPropertiesForGlobal();
+ generateDubboPropertiesForApp();
+ }
+
+ public static void generateDubboPropertiesForGlobal() {
+ String str = "dubbo.registry.address=zookeeper://" + zookeeperHost + ":2181\n" +
+// "dubbo.metadata-report.address=zookeeper://" + zookeeperHost + ":2181\n" +
+ "dubbo.protocol.port=-1\n" +
+// "dubbo.registry.simplified=true\n"+
+ "";
+
+ System.out.println(str);
+
+ try {
+ String path = "/dubbo/config/dubbo/dubbo.properties";
+ if (client.checkExists().forPath(path) == null) {
+ client.create().creatingParentsIfNeeded().forPath(path);
+ }
+ setData(path, str);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void generateDubboPropertiesForApp() {
+ String str = "dubbo.provider.timeout=6666\n" +
+ "dubbo.application.qos.port=33333\n" +
+ "dubbo.service.com.ikurento.user.UserProvider.cluster=failback";
+
+ System.out.println(str);
+
+ try {
+ String path = "/dubbo/config/user-info-server/dubbo.properties";
+ if (client.checkExists().forPath(path) == null) {
+ client.create().creatingParentsIfNeeded().forPath(path);
+ }
+ setData(path, str);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void createNode(String path) throws Exception {
+ client.create().forPath(path);
+ }
+
+ private static void deleteNode(String path) throws Exception {
+ client.delete().forPath(path);
+ }
+
+ private static void setData(String path, String data) throws Exception {
+ client.setData().forPath(path, data.getBytes());
+ }
+}
diff --git a/router/tag/java-server/src/main/java/com/ikurento/user/impl/UserProviderImpl.java b/router/tag/java-server/src/main/java/com/ikurento/user/impl/UserProviderImpl.java
new file mode 100644
index 0000000..0caf910
--- /dev/null
+++ b/router/tag/java-server/src/main/java/com/ikurento/user/impl/UserProviderImpl.java
@@ -0,0 +1,32 @@
+/*
+ * 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.impl;
+
+import com.ikurento.user.User;
+import com.ikurento.user.UserProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserProviderImpl implements UserProvider {
+ private static final Logger LOG = LoggerFactory.getLogger("UserLogger"); //Output to user-server.log
+
+ public User GetUser(String userId) {
+ return new User(userId, "zhangsan", 18);
+ }
+
+}
diff --git a/router/tag/java-server/src/main/resources/META-INF/spring/dubbo.provider.xml b/router/tag/java-server/src/main/resources/META-INF/spring/dubbo.provider.xml
new file mode 100644
index 0000000..5410ef3
--- /dev/null
+++ b/router/tag/java-server/src/main/resources/META-INF/spring/dubbo.provider.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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协议在20880端口暴露服务 -->
+ <!-- dubbo:protocol host="127.0.0.1" / -->
+ <dubbo:protocol id="dubbo" name="dubbo" host="127.0.0.1" port="20010"/>
+ <!-- 声明需要暴露的服务接口 -->
+ <dubbo:service id="aaa" registry="ikurento" timeout="3000" interface="com.ikurento.user.UserProvider"
+ ref="demoService"/>
+
+ <bean id="demoService" class="com.ikurento.user.impl.UserProviderImpl"/>
+
+</beans>
diff --git a/router/tag/java-server/src/main/resources/META-INF/spring/dubbo.provider2.xml b/router/tag/java-server/src/main/resources/META-INF/spring/dubbo.provider2.xml
new file mode 100644
index 0000000..7117b95
--- /dev/null
+++ b/router/tag/java-server/src/main/resources/META-INF/spring/dubbo.provider2.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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协议在20880端口暴露服务 -->
+ <!-- dubbo:protocol host="127.0.0.1" / -->
+ <dubbo:protocol id="dubbo" name="dubbo" host="127.0.0.1" port="20011"/>
+ <!-- 声明需要暴露的服务接口 -->
+ <dubbo:service id="aaa" registry="ikurento" timeout="3000" interface="com.ikurento.user.UserProvider"
+ ref="demoService"/>
+
+ <bean id="demoService" class="com.ikurento.user.impl.UserProviderImpl"/>
+
+</beans>
diff --git a/router/tag/java-server/src/main/resources/log4j.properties b/router/tag/java-server/src/main/resources/log4j.properties
new file mode 100644
index 0000000..806e33d
--- /dev/null
+++ b/router/tag/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
+