Skip to content
Permalink
Browse files
big api change
  • Loading branch information
hufeng committed Jun 12, 2018
1 parent b28e70b commit f97813843a0ae9254c5901baf0dcad670a34cdff
Showing 17 changed files with 221 additions and 230 deletions.
@@ -22,11 +22,11 @@ nodejs 使用原生的 dubbo (dubbo head + hessian body) 协议打通了 dubbo

6. Tracing

7. supported Dubbox
7. Supported Dubbox

8. typescript type definition
8. Typescript type definition

9. convert java dubbo interface to typescript module
9. Convert java dubbo interface to typescript module

## Getting Started

This file was deleted.

This file was deleted.

@@ -0,0 +1,17 @@
const {Dubbo} = require('dubbo2.js/es6');
const service = require('./service');

const dubbo = (module.exports = new Dubbo({
application: {name: 'dubbo-node-consumer'},
register: 'localhost:2181',
service,
}));

//middleware
dubbo.use(async function costTime(ctx, next) {
console.log('before dubbo cost middleware');
const startTime = Date.now();
await next();
const endTime = Date.now();
console.log('end makecostTime->', endTime - startTime);
});
@@ -0,0 +1,17 @@
const {Dubbo} = require('dubbo2.js');
const service = require('./service');

const dubbo = (module.exports = new Dubbo({
application: {name: 'dubbo-node-consumer'},
register: 'localhost:2181',
service,
}));

//cost middleware
dubbo.use(async function costTime(ctx, next) {
console.log('before dubbo cost middleware');
const startTime = Date.now();
await next();
const endTime = Date.now();
console.log('end makecostTime->', endTime - startTime);
});
@@ -0,0 +1,55 @@
const {java} = require('dubbo2.js');

const provider = (module.exports = {});

provider.demoProvider = dubbo =>
dubbo.proxyService({
dubboInterface: 'com.alibaba.dubbo.demo.DemoProvider',
version: '1.0.0',
methods: {
sayHello(name) {
return [java.String(name)];
},

echo() {},

test() {},

getUserInfo() {
return [
java.combine('com.alibaba.dubbo.demo.UserRequest', {
id: 1,
name: 'nodejs',
email: 'node@qianmi.com',
}),
];
},
},
});

provider.basicTypeProvider = dubbo =>
dubbo.proxyService({
dubboInterface: 'com.alibaba.dubbo.demo.BasicTypeProvider',
version: '2.0.0',
methods: {
testBasicType() {
return [
java.combine('com.alibaba.dubbo.demo.TypeRequest', {
map: java.Map({name: 'test'}),
bigDecimal: java.BigDecimal('1000.0000'),
}),
];
},
},
});

provider.errorProvider = dubbo =>
dubbo.proxyService({
dubboInterface: 'com.alibaba.dubbo.demo.ErrorProvider',
version: '1.0.0',
methods: {
errorTest() {
return [];
},
},
});
@@ -1,9 +1,9 @@
const http = require('http');
const {demoService, basicTypeService} = require('./dubbo-es6');
const dubbo = require('./dubbo/dubbo-es6');

const app = http.createServer((req, response) => {
if (req.url === '/dubbo') {
demoService.echo().then(({res, err}) => {
dubbo.service.demoProvider.echo().then(({res, err}) => {
response.end(res);
});
}
@@ -1,8 +1,8 @@
const http = require('http');
const {demoProvider} = require('./dubbo');
const dubbo = require('./dubbo/dubbo');

const app = http.createServer(async (req, res) => {
const hello = await demoProvider.sayHello();
const hello = await dubbo.service.demoProvider.sayHello();
res.end(hello.res);
});

@@ -1,7 +1,6 @@
const Koa = require('koa');
const Router = require('koa-router');
// const {tracer} = require('dubbo2.js');
const {demoProvider, basicTypeProvider, errorProvider} = require('./dubbo');
const dubbo = require('./dubbo/dubbo');

const app = new Koa();
const router = new Router();
@@ -11,36 +10,36 @@ router.get('/', ctx => {
});

router.get('/hello', async ctx => {
const {res, err} = await demoProvider.sayHello('test');
const {res, err} = await dubbo.service.demoProvider.sayHello('test');
ctx.body = err ? err.message : res;
});

router.get('/user', async ctx => {
const {res, err} = await demoProvider.getUserInfo();
const {res, err} = await dubbo.service.demoProvider.getUserInfo();
ctx.body = res || err.message;
});

router.get('/echo', async ctx => {
ctx.body = await demoProvider.echo();
ctx.body = await dubbo.service.demoProvider.echo();
});

router.get('/type', async ctx => {
const {res, err} = await basicTypeProvider.testBasicType();
const {res, err} = await dubbo.service.basicTypeProvider.testBasicType();
ctx.body = res;
});

router.get('/exp', async ctx => {
const {err, res} = await errorProvider.errorTest();
const {err, res} = await dubbo.service.errorProvider.errorTest();
console.log(err);
ctx.body = 'ok';
});

router.get('/tracer', async ctx => {
const {res: hello} = await demoProvider.sayHello('test');
const {res: userInfo} = await demoProvider.getUserInfo();
const {res: hello} = await dubbo.service.demoProvider.sayHello('test');
const {res: userInfo} = await dubbo.service.demoProvider.getUserInfo();

setTimeout(async () => {
await basicTypeProvider.testBasicType();
await dubbo.service.basicTypeProvider.testBasicType();
process.nextTick(() => {
demoProvider.getUserInfo();
});

0 comments on commit f978138

Please sign in to comment.