Coder Social home page Coder Social logo

dubbo-rpc-jsonrpc's Introduction

Build Status

Why HTTP

With the rapid iteration of the Internet, more and more companies choose quick script frameworks such as nodejs, Django and rails to develop web-side applications.

Java is the most suitable for back-end service, which resulting in a lot of cross-language invocation requirements.

While HTTP and JSON are naturally suitable as cross-language standards, all languages have mature class libraries for them.

Although Dubbo's asynchronous long connection protocol is efficient, in scripting languages this loss of efficiency is not important.

Why Not RESTful

Dubbo has made an attempt on the RESTful interface, but there is some difference between the REST architecture and the original RPC architecture of Dubbo.

The difference is that the REST architecture needs the definition of resources and we should operate the resources using the basic HTTP methods —— GET, POST, PUT, DELETE.

Dubbo needs to redefine the properties of the interface, which is a big burden on the original interface migration of Dubbo.

In contrast, RESTful is more appropriate for calls between Internet systems, and RPC is more appropriate for calls within a system, so we used JsonRPC which is more consistent with the Dubbo concept.

dubbo-rpc-jsonrpc

maven dependency:

<dependency>
    <groupId>com.qianmi</groupId>
    <artifactId>dubbo-rpc-jsonrpc</artifactId>
    <version>1.0.1</version>
</dependency>

Configuration:

Define jsonrpc protocol:

 <dubbo:protocol name="jsonrpc" port="8080" server="jetty" />

Set default protocol:

<dubbo:provider protocol="jsonrpc" />

Set service protocol:

<dubbo:service protocol="jsonrpc" />

Multi port:

<dubbo:protocol id="jsonrpc1" name="jsonrpc" port="8080" />
<dubbo:protocol id="jsonrpc2" name="jsonrpc" port="8081" />

Multi protocol:

<dubbo:protocol name="dubbo" port="20880" />
<dubbo:protocol name="jsonrpc" port="8080" />
<dubbo:service id="helloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" protocol="dubbo,jsonrpc" />

Jetty Server: (default)

<dubbo:protocol ... server="jetty" />

or the latest version of jetty:
<dubbo:protocol ... server="jetty9" />

Maven:

<dependency>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty</artifactId>
  <version>6.1.26</version>
</dependency>

Servlet Bridge Server: (recommend)

<dubbo:protocol ... server="servlet" />

web.xml:

<servlet>
         <servlet-name>dubbo</servlet-name>
         <servlet-class>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet</servlet-class>
         <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
         <servlet-name>dubbo</servlet-name>
         <url-pattern>/*</url-pattern>
</servlet-mapping>

Be careful if you are using a servlet to send requests:

The protocol port <dubbo:protocol port="8080" /> must be the same as the port of the servlet container. The protocol context path <dubbo:protocol contextpath="foo" /> must be the same as the servlet application context path.

CORS(Cross-origin resource sharing):

<dubbo:protocol name="jsonrpc" ...  />
	<dubbo:parameter key="cors" value="true" />
</dubbo:protocol>

Example

JAVA API

public interface PhoneNoCheckProvider {
    /**
     * check if the number is limited
     * @param operators  operators
     * @param no  number
     * @param userid  the user identity
     * */
    boolean isPhoneNoLimit(Operators operators, String no, String userid);
}

Client

curl -i -H 'content-type: application/json' -X POST -d '{"jsonrpc": "2.0", "method": "isPhoneNoLimit", "params": [ "MOBILE", "130000", "A001"],
         "id": 1 }' 'http://127.0.0.1:18080/com.qianmi.api.PhoneNoCheckProvider'

Python Client Example

import httplib
import json

__author__ = 'caozupeng'


def raw_client(app_params):
    headers = {"Content-type": "application/json-rpc",
               "Accept": "text/json"}
    h1 = httplib.HTTPConnection('172.19.32.135', port=18080)
    h1.request("POST", '/com.qianmi.ofdc.api.phone.PhoneNoCheckProvider', json.dumps(app_params), headers)
    response = h1.getresponse()
    return response.read()


if __name__ == '__main__':
    app_params = {
        "jsonrpc": "2.0",
        "method": "isPhoneNoLimit",
        "params": ["MOBILE", "130000", "A001"],
        "id": 1
    }
    print json.loads(raw_client(app_params), encoding='utf-8')

Python client

https://github.com/QianmiOpen/dubbo-client-py

Node.js client

https://github.com/QianmiOpen/dubbo-node-client

Examples for Client server

https://github.com/JoeCao/dubbo_jsonrpc_example
run with docker

Browser call

You need to enable CORS support as described above, see https://github.com/datagraph/jquery-jsonrpc

Documentation

JSON-RPC 2.0 Specification

jsonrpc4j

dubbo procotol

dubbo-rpc-jsonrpc's People

Contributors

albumenj avatar aqlu avatar chickenlj avatar joecao avatar lxylona avatar peace0phmind avatar shevawen avatar wuwen5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dubbo-rpc-jsonrpc's Issues

serverlet

作者你好,感谢你回复。
配置感觉我有一步骤不对,
文中说到的:“
注意,如果使用servlet派发请求:

协议的端口必须与servlet容器的端口相同, 协议的上下文路径必须与servlet应用的上下文路径相同。“
这句话怎么理解 以及配置呢,感谢回复谢谢

a proposal for moving this project

hello, guys, this project for a rpc component with jsonrpc, and then we can create more component in this way, such as xmlrpc, pb, grpc, turbo,hprose etc, then we need create many root projects in apache org.

So, I think we need think about moving this project in two ways:

  • move the rpc component to dubbo-rpc module of dubbo project
  • or create a new root project incubator-dubbo-rpc-component, all new rpc component from community will be here.

How about this idea, guys?

support org.apache.dubbo 2.7.x

current version of dubbo-rpc-jsonrpc is write for com.alibaba.dubbo version 2.4.x - 2.6.x

could someone rewrite the code for support org.apache.dubbo 2.7.x

change

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo_version}</version>
            <optional>true</optional>
        </dependency>

into

        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo_version}</version>
            <optional>true</optional>
        </dependency>

and rewrite the JsonRpcProtocol class there is no more com.alibaba.dubbo.rpc.protocol.AbstractProxyProtocol

请问如何在spring boot上配置?

其他没有问题,只有最后一步在web.xml上配转发器的那个不知道怎么配了,spring boot没有web.xml,普通的dubbo协议是通的

关于 跨域支持

想直接将服务抛给 浏览器 里的 JS,需要跨域支持,我试着这么做了

if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
    response.setHeader(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    response.setHeader(CrossOriginFilter.ACCESS_CONTROL_ALLOW_METHODS_HEADER, "POST");
    response.setHeader(CrossOriginFilter.ACCESS_CONTROL_ALLOW_HEADERS_HEADER, "Content-Type");
    response.setStatus(200);
} else if (request.getMethod().equalsIgnoreCase("POST")) {
    response.setHeader(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*");
    RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
    try {
        skeleton.handle(request.getInputStream(), response.getOutputStream());
    } catch (Throwable e) {
        throw new ServletException(e);
    }
} else {
    response.setStatus(500);
}

是可以的,但是我需要一个开关,可以放到protocol配置里么?像下面(我是用js做ioc启动的)

protocol : {
    type : 'com.alibaba.dubbo.config.ProtocolConfig',
    fields : {
        name : 'jsonrpc',
        port : 9090,
        server : 'jetty',
        cors: true
    }
}

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.