Skip to content

Repository files navigation

About Rayson

An API server and it's development framework which support cross-platform communication and Rapid Application Development (RAD).

Features

  1. Simple

    • Based on standard HTTP protocol (Support SSL)
    • Serializing using rapid an compressed structured data by default
    • Using Java Interface to define API
  2. Light weight

    • Embedded server
    • Dependent on one third party library only
  3. High performance

    • Pure NIO implementation
    • Multiple threads intelligent scheduling
  4. Easy to use

    • Client side using Java Interface directly to call remote API service
    • Concise Interfaces used both in server side and client side
    • Developer can focus on their business logic only, but not the underling communication and scheduling detail

Code examples

  • Server side
  1. Define API protocol
@ServicepublicinterfaceSimpleProtocolextendsProtocol {
/** * Echo received message.  * @param msg The message to be echo. * @return Return the given message. * @throws IOException */publicStringecho(Stringmsg) throwsIOException, RpcException;
/** * Echo received message. * @param msg The message to be echo. * @return Return the given message. * @throws IOException */publicbyte[] echo2(byte[] msg) throwsIOException, RpcException;
} 
  1. Implements API protocol
publicclassSimpleServiceimplementsSimpleProtocol {
@OverridepublicStringecho(finalStringmsg) throwsRpcException {
returnmsg;
} @Overridepublicbyte[] echo2(byte[] msg) throwsRpcException {
returnmsg;
}
}
  1. Start the server and register service.
publicstaticvoidmain(finalString[] args) throwsException {
finalRaysonServerserver = newRaysonServer(8080);
server.registerService(newSimpleService());
server.start();
}
  • Client side
  1. Java client RPC invoing
publicstaticvoidmain(finalString[] args) throwsException {
finalRaysonServerAddressserverAddr = newRaysonServerAddress("localhost", 8080);
SimpleProtocolsimpleProtocol = Rayson.createProxy(serverAddr, SimpleProtocol.class);
try {
StringechoMsg = simpleProtocol.echo("Hello World");
System.out.println(echoMsg);
} catch (IOExceptione) {
System.err.println("Network error occurred");
} catch (RpcExceptione) {
System.err.println("Invoking RPC got logic error: error_code: " + e.getCode() + " error_message: " + e.getMessage());
}
}	
  1. Bash script invoking by curl
curl -v "http://localhost:8080/org.rayson.demo.simple.api.SimpleProtocol/echo?msg=Hello%20World"> GET /org.rayson.demo.simple.api.SimpleProtocol/echo?msg=Hello%20World HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*>< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Content-Length: 13
<"Hello World"

Performance table

Rayson server performance testing.

  • Testing environment

MacBook Pro
CPU: 2 GHz Intel Core i5 2 Cores
Memory: 8 GB 1867 MHz LPDDR3

  • Testing result
ThreadsCall(Per Thread)Requests/Second
110001429
510001000
1100004274
5100002421
5010000430
11000007576
51000003968
50100000545

Copyright Creativor Studio© 2020

About

An Simple and Fast API development framework

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages