Giter Site home page Giter Site logo

luruozhou / dubbo-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apache/dubbo-js

0.0 1.0 0.0 30.73 MB

Node.js native Apache Dubbo client on hessian

Home Page: https://dubbo.apache.org

License: Apache License 2.0

JavaScript 8.59% Java 3.43% TypeScript 87.27% Makefile 0.59% CSS 0.11%

dubbo-js's Introduction

Apache Dubbo-js

Dubbo-js, using Node.js to embrace the Dubbo ecosystem. See this Demo to find how intelligent this project is.

Features

  • Various transport protocols (Hessian, JSON-RPC etc.) supports
  • Tracing (Runtime information, Call Stack)
  • Multiple registry centers (Zookeeper, Nacos, Redis) supports or connecting to services directly
  • Extensibility, inspired from Koa Middleware
  • Builtin reconnection strategy
  • Typescript type definitions
  • Tools to automatically translate Java interfaces to Typescript type definitions
  • Dubbox supports

Architecture

Getting Started

yarn add dubbo2.js

Usage

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 'dubbo2.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: '[email protected]',
          }),
        ];
      },
    },
  });

// integrate the service in demoProvider with dubbo object constructor
const service = {
  demoProvider,
};

const dubbo = new Dubbo<typeof service>({
  // ....other parameters
  service,
});

For contributors

If you'd like to contribute, it's a good start to follow below commands to get a locally runnable project.

# start zookeeper cluster
docker-compose up

# start java
cd java/dubbo-demo
mvn clean install
cd java/dubbo-demo/dubbo-demo-provider
mvn clean package
java -jar target/dubbo-demo-provider-2.6.3-jar-with-dependencies.jar

# build
make

# start node
cd example/hello-koa
npm run debug:start

# test /hello
curl http://localhost:3000/hello

Next steps

Guides

Reporting bugs

Please follow the template for reporting any issues.

Knowledge Sharing

2019-meetup by hufeng

Thanks

Dubbo-js will not work without:

Many thanks to their authors fengmk2 and dead-horse.

License

Apache Dubbo is under the Apache 2.0 license. See the LICENSE file for details.

dubbo-js's People

Contributors

atarismio avatar binlaniua avatar chaoshimeng avatar chickenlj avatar crab666 avatar creasy2010 avatar dsky1990 avatar godkun avatar hsiaosiyuan0 avatar hufeng avatar jasonjoo2010 avatar ohiamfine avatar ralf0131 avatar sunchuanleihit avatar wushanchao avatar zhcsyncer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.