An API server and it's development framework which support cross-platform communication and Rapid Application Development (RAD).
Simple
- Based on standard HTTP protocol (Support SSL)
- Serializing using rapid an compressed structured data by default
- Using Java Interface to define API
Light weight
- Embedded server
- Dependent on one third party library only
High performance
- Pure NIO implementation
- Multiple threads intelligent scheduling
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
- Server side
- 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;
} - Implements API protocol
publicclassSimpleServiceimplementsSimpleProtocol {
@OverridepublicStringecho(finalStringmsg) throwsRpcException {
returnmsg;
} @Overridepublicbyte[] echo2(byte[] msg) throwsRpcException {
returnmsg;
}
}- Start the server and register service.
publicstaticvoidmain(finalString[] args) throwsException {
finalRaysonServerserver = newRaysonServer(8080);
server.registerService(newSimpleService());
server.start();
}- Client side
- 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());
}
} - 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"Rayson server performance testing.
- Testing environment
MacBook Pro
CPU: 2 GHz Intel Core i5 2 Cores
Memory: 8 GB 1867 MHz LPDDR3
- Testing result
| Threads | Call(Per Thread) | Requests/Second |
|---|---|---|
| 1 | 1000 | 1429 |
| 5 | 1000 | 1000 |
| 1 | 10000 | 4274 |
| 5 | 10000 | 2421 |
| 50 | 10000 | 430 |
| 1 | 100000 | 7576 |
| 5 | 100000 | 3968 |
| 50 | 100000 | 545 |
Copyright Creativor Studio© 2020