Skip to content
Permalink
Browse files
refactor fullstack example sperate nacos and zookeeper
  • Loading branch information
hufeng committed Jun 9, 2021
1 parent 5f13bba commit 66c9a2c990b590333006658faf05e262c72e6ebe
Showing 11 changed files with 112 additions and 43 deletions.
@@ -66,25 +66,25 @@ const demoSerivce = dubbo.proxService({
### connect dubbo directly

```typescript
import {DirectlyDubbo, java} from 'apache-dubbo-js';
import { DirectlyDubbo, java } from 'apache-dubbo-js'
import {
DemoProvider,
DemoProviderWrapper,
IDemoProvider,
} from './providers/com/alibaba/dubbo/demo/DemoProvider';
import {UserRequest} from './providers/com/alibaba/dubbo/demo/UserRequest';
IDemoProvider
} from './providers/com/alibaba/dubbo/demo/DemoProvider'
import { UserRequest } from './providers/com/alibaba/dubbo/demo/UserRequest'
const dubbo = DirectlyDubbo.from({
dubboAddress: 'localhost:20880',
dubboVersion: '2.0.0',
dubboInvokeTimeout: 10,
});
dubboInvokeTimeout: 10
})
const demoService = dubbo.proxyService<IDemoProvider>({
dubboInterface: 'com.alibaba.dubbo.demo.DemoProvider',
methods: DemoProviderWrapper,
version: '1.0.0',
});
version: '1.0.0'
})
```

## When dubbo was ready?
@@ -121,13 +121,13 @@ const dubbo = Dubbo.from(/*...*/);
## dubbo's subscriber

```javascript
const dubbo = Dubbo.from(/*...*/);
const dubbo = Dubbo.from(/*...*/)
dubbo.subscribe({
onTrace(msg: ITrace) {
console.log(msg);
},
});
console.log(msg)
}
})
```

you should get runtime trace info
@@ -279,8 +279,8 @@ you should get runtime trace info
at TCP._handle.close [as _onclose] (net.js:541:12) }
{ type: 'ERR',
msg: Error: 172.19.6.203:20880's pool socket-worker had all closed. delete 172.19.6.203:20880
at ServerAgent._clearClosedPool (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/server-agent.js:66:33)
at Object.onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/server-agent.js:51:34)
at ServerAgent._clearClosedPool (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/serverNacos-agent.js:66:33)
at Object.onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/serverNacos-agent.js:51:34)
at SocketWorker._onClose (/Users/hufeng/Github/dubbo2.js/packages/dubbo/es7/socket-worker.js:97:34)
at Socket.emit (events.js:180:13)
at TCP._handle.close [as _onclose] (net.js:541:12) }
@@ -5,15 +5,15 @@ sidebar_label: Troubleshooting
---

```javascript
import {Dubbo} from 'apache-dubbo-js';
import { Dubbo } from 'apache-dubbo-js'
```

默认导入的 apache-dubbo-js 是按照 es2017 进行编译的,支持 node7.10 以上。

如果更低的 node 版本,可以使用

```javascript
import {Dubbo} from 'apache-dubbo-js/es6';
import { Dubbo } from 'apache-dubbo-js/es6'
```

## 报错了,为什么呢?
@@ -35,13 +35,13 @@ DEBUG=dubbo* pm2 start xxxx
最普通

```sh
DEBUG=dubbo* node server.js
DEBUG=dubbo* node serverNacos.js
```

## log example

```text
❯ DEBUG=dubbo* node server.js
❯ DEBUG=dubbo* node serverNacos.js
dubbo:queue new Queue +0ms
dubbo:bootstrap dubbo2.js version :=> 2.1.5 +0ms
dubbo:bootstrap initial:|> { application: { name: 'dubbo-node-consumer' },
@@ -105,9 +105,9 @@ DEBUG=dubbo* node server.js
dubbo:zookeeper version: '1.0.0',
dubbo:zookeeper group: '' } ] } +0ms
dubbo:scheduler get agent address:=> Set { '172.19.6.203:20880' } +90ms
dubbo:server-agent agerntAddrs: Set { '172.19.6.203:20880' } +0ms
dubbo:serverNacos-agent agerntAddrs: Set { '172.19.6.203:20880' } +0ms
dubbo:zookeeper init providerMap and agentSet +5ms
dubbo:server-agent create ServerAgent: 172.19.6.203:20880 +0ms
dubbo:serverNacos-agent create ServerAgent: 172.19.6.203:20880 +0ms
{ type: 'INFO',
msg: 'ServerAgent create socket-pool: 172.19.6.203:20880' }
dubbo:socket-pool new:|> {
@@ -1,6 +1,6 @@
# Nacos Docker

![Docker Pulls](https://img.shields.io/docker/pulls/nacos/nacos-server.svg?maxAge=60480)
![Docker Pulls](https://img.shields.io/docker/pulls/nacos/nacos-serverNacos.svg?maxAge=60480)

This project contains a Docker image meant to facilitate the deployment of [Nacos](https://github.com/alibaba/nacos).

@@ -10,11 +10,11 @@ This project contains a Docker image meant to facilitate the deployment of [Naco

- build:Nacos makes the source code of the docker image
- env: Environment variable file for compose yaml
- example: Docker compose example for Nacos server
- example: Docker compose example for Nacos serverNacos

## Precautions

- The **database master-slave image** has been removed, after the latest `nacos/nacos-server:latest` image. For specific reasons, refer to [Removing the Master-Slave Image Configuration](https://github.com/nacos-group/nacos-docker/wiki/%E7%A7%BB%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%BB%E4%BB%8E%E9%95%9C%E5%83%8F%E9%85%8D%E7%BD%AE)
- The **database master-slave image** has been removed, after the latest `nacos/nacos-serverNacos:latest` image. For specific reasons, refer to [Removing the Master-Slave Image Configuration](https://github.com/nacos-group/nacos-docker/wiki/%E7%A7%BB%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%BB%E4%BB%8E%E9%95%9C%E5%83%8F%E9%85%8D%E7%BD%AE)
- Since Nacos 1.3.1 version, the database storage has been upgraded to 8.0, and it is backward compatible

## Quick Start
@@ -81,8 +81,8 @@ Run the following command:
| MODE | cluster/standalone | cluster/standalone default **cluster** |
| NACOS_SERVERS | nacos cluster address | eg. ip1:port1 ip2:port2 ip3:port3 |
| PREFER_HOST_MODE | Whether hostname are supported | hostname/ip default **ip** |
| NACOS_APPLICATION_PORT | nacos server port | default **8848** |
| NACOS_SERVER_IP | custom nacos server ip when network was mutil-network | |
| NACOS_APPLICATION_PORT | nacos serverNacos port | default **8848** |
| NACOS_SERVER_IP | custom nacos serverNacos ip when network was mutil-network | |
| SPRING_DATASOURCE_PLATFORM | standalone support mysql | mysql / empty default empty |
| MYSQL_SERVICE_HOST | mysql host | |
| MYSQL_SERVICE_PORT | mysql database port | default : **3306** |
@@ -104,7 +104,7 @@ Run the following command:
| JVM_MS | -XX:MetaspaceSize | default :128m |
| JVM_MMS | -XX:MaxMetaspaceSize | default :320m |
| NACOS_DEBUG | enable remote debug | y/n default :n |
| TOMCAT_ACCESSLOG_ENABLED | server.tomcat.accesslog.enabled | default :false |
| TOMCAT_ACCESSLOG_ENABLED | serverNacos.tomcat.accesslog.enabled | default :false |
| NACOS_AUTH_SYSTEM_TYPE | The auth system to use, currently only 'nacos' is supported | default :nacos |
| NACOS_AUTH_ENABLE | If turn on auth system | default :false |
| NACOS_AUTH_TOKEN_EXPIRE_SECONDS | The token expiration in seconds | default :18000 |
@@ -1,6 +1,6 @@
# Nacos Docker

本项目是 [Nacos](https://github.com/alibaba/nacos) Server 的 docker 镜像的 build 源码,以及 Nacos server 在 docker 的单机和集群的运行例子.
本项目是 [Nacos](https://github.com/alibaba/nacos) Server 的 docker 镜像的 build 源码,以及 Nacos serverNacos 在 docker 的单机和集群的运行例子.

## 项目目录

@@ -14,15 +14,15 @@

### 注意事项

- 从最新的 nacos:nacos-server/latest 镜像以后,移除了数据库主从镜像,具体原因请参考[移除主从镜像配置](https://github.com/nacos-group/nacos-docker/wiki/%E7%A7%BB%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%BB%E4%BB%8E%E9%95%9C%E5%83%8F%E9%85%8D%E7%BD%AE)
- 从最新的 nacos:nacos-serverNacos/latest 镜像以后,移除了数据库主从镜像,具体原因请参考[移除主从镜像配置](https://github.com/nacos-group/nacos-docker/wiki/%E7%A7%BB%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%BB%E4%BB%8E%E9%95%9C%E5%83%8F%E9%85%8D%E7%BD%AE)
- 从 Nacos 1.3.1 版本开始,数据库存储已经升级到 8.0,并且它向下兼容

## 快速开始

打开命令窗口执行:

```powershell
docker run --name nacos-standalone -e MODE=standalone -p 8848:8848 -d nacos/nacos-server:latest
docker run --name nacos-standalone -e MODE=standalone -p 8848:8848 -d nacos/nacos-serverNacos:latest
```

## 其他使用方式
@@ -94,7 +94,7 @@
| JVM_MS | -XX:MetaspaceSize | 默认 :128m |
| JVM_MMS | -XX:MaxMetaspaceSize | 默认 :320m |
| NACOS_DEBUG | enable remote debug | y/n 默认 :n |
| TOMCAT_ACCESSLOG_ENABLED | server.tomcat.accesslog.enabled | 默认 :false |
| TOMCAT_ACCESSLOG_ENABLED | serverNacos.tomcat.accesslog.enabled | 默认 :false |
| NACOS_AUTH_SYSTEM_TYPE | 权限系统类型选择,目前只支持 nacos 类型 | 默认 :nacos |
| NACOS_AUTH_ENABLE | 是否开启权限系统 | 默认 :false |
| NACOS_AUTH_TOKEN_EXPIRE_SECONDS | token 失效时间 | 默认 :18000 |
@@ -27,9 +27,9 @@ WORKDIR /$BASE_DIR
RUN set -x \
&& yum update -y \
&& yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel wget iputils nc vim libcurl
RUN wget https://github.com/alibaba/nacos/releases/download/${NACOS_VERSION}/nacos-server-${NACOS_VERSION}.tar.gz -P /home
RUN tar -xzvf /home/nacos-server-${NACOS_VERSION}.tar.gz -C /home \
&& rm -rf /home/nacos-server-${NACOS_VERSION}.tar.gz /home/nacos/bin/* /home/nacos/conf/*.properties /home/nacos/conf/*.example /home/nacos/conf/nacos-mysql.sql
RUN wget https://github.com/alibaba/nacos/releases/download/${NACOS_VERSION}/nacos-serverNacos-${NACOS_VERSION}.tar.gz -P /home
RUN tar -xzvf /home/nacos-serverNacos-${NACOS_VERSION}.tar.gz -C /home \
&& rm -rf /home/nacos-serverNacos-${NACOS_VERSION}.tar.gz /home/nacos/bin/* /home/nacos/conf/*.properties /home/nacos/conf/*.example /home/nacos/conf/nacos-mysql.sql
RUN yum autoremove -y wget \
&& ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo $TIME_ZONE > /etc/timezone \
&& yum clean all
@@ -27,9 +27,9 @@
# limitations under the License.

# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
serverNacos.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
serverNacos.contextPath=/nacos
serverNacos.port=${NACOS_APPLICATION_PORT:8848}
spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:""}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
@@ -53,13 +53,13 @@ nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey01234567890
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}

server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
serverNacos.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
serverNacos.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
serverNacos.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/serverNacos/**
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
@@ -16,15 +16,15 @@ version:1.3.0

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server,discovery]
# nacos.core.member.lookup.type=[file,address-serverNacos,discovery]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for DiscoveryMemberLookup
# If you want to use cluster node self-discovery, turn this parameter on
# nacos.member.discovery=false
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
# Maximum number of retries to query the address serverNacos upon initialization
# nacos.core.address-serverNacos.retry=5

#*************** JRaft Related Configurations ***************#

File renamed without changes.
@@ -0,0 +1,41 @@
/*
* 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.
*/

import Koa from 'koa'
import { Dubbo } from '@apache/dubbo-consumer'
import { Zk } from '@apache/dubbo-registry'
import services from './service'

const dubbo = new Dubbo<typeof services>({
application: {
name: 'hello-api'
},
registry: Zk({ connect: 'localhost:2181' }),
services
})

const server = new Koa()
server.use(async (ctx) => {
const { res, err } = await dubbo.service.helloService.hello('dubbo-js')
console.log(res, err)
ctx.body = {
res,
err: err?.message
}
})
server.listen(3000)
console.log('hello-api start at port 6000....')
File renamed without changes.
@@ -0,0 +1,28 @@
/*
* 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.
*/

import { DubboService } from '@apache/dubbo-service'
import { Zk } from '@apache/dubbo-registry'
import services from './service'
;(async function main() {
const dubbo = new DubboService({
registry: Zk({ connect: 'localhost:2181' }),
services
})
await dubbo.ready()
console.log('dubbo server start....')
})()

0 comments on commit 66c9a2c

Please sign in to comment.