Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

mariomac/easyrpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easyrpc

Automatic RPC stubs generation for (at the moment) Java.

Features:

  • Easy to adopt. No need for configuration files. Just import libraries and use them.
  • Client-side and server-side stubs generation at runtime
  • Communication through HTTP and AMQP 1.0. Extensible to more communication protocols.
  • JSON-RPC 2.0 serialization. Extensible to other serialization (SOAP, ProtoBuf...)
  • Serializes POJOs and Collections thanks to Jackson Databind

How it works:

Server side

Step 1: create a service interface

public interface IFace {
    int add(int a, int b);
    String concat(String s1, String s2);
    int[] doubleArray(int[] arr);
}

Step 2: implement the interface

public class Implementation implements IFace {
    @Override
    public int add(int a, int b) {
        return a+b;
    }
    @Override
    public String concat(String s1, String s2) {
        return s1+s2;
    }
    @Override
    public int[] doubleArray(int[] arr) {
        for(int i = 0 ; i < arr.length ; i++) {
            arr[i] = arr[i] * 2;
        }
        return arr;
    }
}

Step 3: instantiate the server.

E.g. JSON-RPC 2.0 over HTTP:

RpcServer server = new RpcServer(
                        new HttpService(8080,"/rpc"),
                        new JSONCallee());

E.g. JSON-RPC 2.0 over AMQP:

RpcServer = new RpcServer(
	            	new AmqpService(new URI("amqp://localhost:5672"), "rpcQueue"),
				    new JSONCallee());

Step 4: register the service through the implementing class and start the service

server.addEndpoint(new Implementation());
server.start();

Client side

Step 1: get the interface IFace. This must be provided by the service provider by sharing, for example, the source code or a compiled jar binary.

Step 2: instantiate the runtime stub generator for the client (in the example, it enables the communication through HTTP and marshalls the RPC info in JSON-RPC 2.0):

ClientFactory stubGenerator = new ClientFactory(
                                new HttpClient("server.address.com", 8080, "/rpc"),
                                new JSONCaller());

Step 3: generate a client class:

IFace obj = stubGenerator.instantiate(IFace.class);

Step 4: use the service:

int result = obj.add(2,3);

Known Limitations

  • The method names for every interface must be unique.

  • If the service modifies the value of an object passed as parameter, the client won't see such changes.

  • AMQP: not ready for sending messages at the same time from multiple thread. At the moment they are internally synchronized to be sent serially.

Si te gustan mis aportaciones a github, quizás te gustará mi libro Del bit a la Nube

Troubleshooting

  • If you get the next exception with AMQP:

      java.lang.RuntimeException: javax.naming.NamingException: Unable to load property file: . [Root exception is java.io.FileNotFoundException:  (No such file or directory)]
    

    ... and you don't know what to do, just point the System property "Context.PROVIDER_URL" (or "java.naming.provider.url" to any reachable directory).

		System.setProperty(Context.PROVIDER_URL,"file:/tmp");

About

Automatic RPC stubs for Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages