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
 
@Service
public interface SimpleProtocol extends Protocol {
	/**
	 * Echo received message. 
	 * @param msg The message to be echo.
	 * @return Return the given message.
	 * @throws IOException
	 */
	public String echo(String msg) throws IOException, RpcException;
	/**
	 * Echo received message.
	 * @param msg The message to be echo.
	 * @return Return the given message.
	 * @throws IOException
	 */
	public byte[] echo2(byte[] msg) throws IOException, RpcException;
} - Implements API protocol
 
public class SimpleService implements SimpleProtocol {
	@Override
	public String echo(final String msg) throws RpcException {
		return msg;
	}  
	@Override
	public byte[] echo2(byte[] msg) throws RpcException {
		return msg;
	}
}- Start the server and register service.
 
public static void main(final String[] args) throws Exception {
	final RaysonServer server = new RaysonServer(8080);
	server.registerService(new SimpleService());
	server.start();
}- Client side
 
- Java client RPC invoing
 
public static void main(final String[] args) throws Exception {
	final RaysonServerAddress serverAddr = new RaysonServerAddress("localhost", 8080);
	SimpleProtocol simpleProtocol = Rayson.createProxy(serverAddr, SimpleProtocol.class);
	try {
		String echoMsg = simpleProtocol.echo("Hello World");
		System.out.println(echoMsg);
	} catch (IOException e) {
		System.err.println("Network error occurred");
	} catch (RpcException e) {
		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