The Json rpc module of Apache Dubbo project

Clone this repo:
  1. 51f0667 Delete .travis.yml by Albumen Kevin · 1 year, 4 months ago master
  2. d14a387 Merge pull request #18 from Lxylona/master by ken.lj · 6 years ago
  3. c65be94 Update by ken.lj · 6 years ago
  4. 74dd732 correction by Lxylona · 6 years ago
  5. ff36932 correction by Lxylona · 6 years ago

Build Status


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.


maven dependency:



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="" version="1.0.0" protocol="dubbo,jsonrpc" />

Jetty Server: (default)

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

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



Servlet Bridge Server: (recommend)

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



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" />



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);


curl -i -H 'content-type: application/json' -X POST -d '{"jsonrpc": "2.0", "method": "isPhoneNoLimit", "params": [ "MOBILE", "130000", "A001"],
         "id": 1 }' ''

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('', port=18080)
    h1.request("POST", '/', json.dumps(app_params), headers)
    response = h1.getresponse()

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

Node.js client

Examples for Client server
run with docker

Browser call

You need to enable CORS support as described above, see


JSON-RPC 2.0 Specification


dubbo procotol