commit | ebf4cc6cca9ff4dc86d924f74697cdb2fc261e24 | [log] [tgz] |
---|---|---|
author | 胡锋 <fengmi99@gmail.com> | Tue Dec 17 16:15:18 2019 +0800 |
committer | GitHub <noreply@github.com> | Tue Dec 17 16:15:18 2019 +0800 |
tree | 415f146cfcefc3ea565e8c484fd30c913b5b876d | |
parent | d0eac49113280035bb64dc71a136bcacbe5054a7 [diff] | |
parent | fe4c91227d724103c82fe2d886259dc6358bfa04 [diff] |
Merge pull request #178 from creasy2010/master Move jexpose.jar to the outside
Dubbo-js, using Node.js to embrace the Dubbo ecosystem. See this Demo to find how intelligent this project is.
yarn add dubbo-js
Below code snippet shows how to work with the typescript type definitions which automatically translated from Java interfaces.
// ===================== service.ts ================== // generated by interpret tools import {BasicTypeProvider} from './providers/com/alibaba/dubbo/demo/BasicTypeProvider'; import {DemoProvider} from './providers/com/alibaba/dubbo/demo/DemoProvider'; import {ErrorProvider} from './providers/com/alibaba/dubbo/demo/ErrorProvider'; export default { BasicTypeProvider, DemoProvider, ErrorProvider, }; // =============== dubbo.ts ======================== import {Dubbo} from 'dubbo2.js'; import service from './service'; // create dubbo object const dubbo = new Dubbo<typeof service>({ application: {name: 'node-dubbo'}, // zookeeper address register: 'localhost:2181', service, }); // main method (async () => { let {res, err} = await dubbo.service.DemoProvider.sayHello('node'); // print {err: null, res:'hello node from dubbo service'} ({res, err} = await dubbo.service.DemoProvider.echo()); // print {err: null, res: 'pang'} ({res, err} = await dubbo.service.DemoProvider.getUserInfo()); // print {status: 'ok', info: { id: '1', name: 'test' }, err: null} })();
The automatically translated typescript type definitions are not necessary, below code snippet demonstrates how to use dubbo-js without them.
// create the service to be injected import {Dubbo} from 'dubbo-js'; const 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', }), ]; }, }, }); // integrate the service in demoProvider with dubbo object constructor const service = { demoProvider, }; const dubbo = new Dubbo<typeof service>({ // ....other parameters service, });
Make sure java, maven, docker, Node, Yarn is installed locally. If you‘d like to contribute, it’s a good start to follow below commands to get a locally runnable project.
# cd root dir cd dubbo-js # start java dubbo service chmod 755 ./start_dubbo_service.sh sh ./start_dubbo_service.sh # build package module make # start node cd example/hello-koa # install node modules yarn # start web yarn run debug:start # test /hello curl http://localhost:3000/hello # or hello-egg example cd example/hello-egg yarn yarn run dev # test /hello http://127.0.0.1:7001/hello
cd dubbo-js sh ./start_dubbo_service.sh yarn make yarn run test
git clone https://github.com/apache/dubbo-js.git cd dubbo-js npm install -g lerna lerna bootstrap make build-dubbo
Please follow the template for reporting any issues.
Dubbo-js will not work without:
Many thanks to their authors fengmk2 and dead-horse.
Apache Dubbo is under the Apache 2.0 license. See the LICENSE file for details.