Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

RSocket SDK Stack

linux_china edited this page Mar 8, 2020 · 11 revisions

RSocket SDK Stack

RSocket作为一个标准的协议,目前支持各种主流开发语言的SDK对接:

  • Java语言: 支持Kotlin, Groovy, Scala等JVM之上语言
  • JavaScript: 同时支持浏览器端JavaScript和Node.js后端
  • Rust: 支持WebAssembly对接
  • RSocket并没有限制数据流格式,你可以根据实际场景选择各种序列化框架

多语言SDK的Proxy模式介绍

RSocket提供了非常多语言的SDK,那么如何让各种语言SDK调用更能和语言贴近(Language Native),这里我们建议使用Proxy模式。 Proxy模式是将对象的函数调用通过Proxy机制转换到用户自定义的行为处理上,也就是通常说的Unknown method call和method missing。

让我们看一下各个语言对应的Proxy机制

  • Java Proxy InvocationHandler
public class DynamicInvocationHandler implements InvocationHandler {
 
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) 
    
    }
}
  • JavaScript Proxy对象
function constructInvocationHandler(obj) {
    let handler = {
        get(target, methodName) {
            let serviceName = target.serviceMapping.serviceName;
            return (...args) => {
                console.log(serviceName)
                console.log(methodName)
                console.log(args);
            }
        }
    };
    return new Proxy(obj, handler);
}
  • PHP __call
   public function __call($name, $args)
    {
        echo "Calling $name $args[0]";
    }
  • Ruby' method_missing hook
def method_missing(m, *args, &block) 
   m_to_s
end
  • Python的__getattr__
class PythonInvocationHandler(object):
    def __init__(self, service_name):
        self.service_name = service_name
        
    def __getattr__(self, name):
        def _missing(*args, **kwargs):
            print "A missing method was called."
            print "The object was %r, the method was %r. " % (self, name)
            print "It was called with %r and %r as arguments" % (args, kwargs)
        return _missing

更多语言的Proxy实现机制介绍在这里: https://rosettacode.org/wiki/Respond_to_an_unknown_method_call

Todo

  • RSocket SDK for PHP based on ReactPHP
  • RSocket C SDK for IoT

RSocket

Network Protocol

  • Binary: byte stream
  • Async message
  • Multi transports
  • Reactive Semantics

Symmetric interactions

  • request/response
  • request/stream
  • fire-and-forget
  • channel

Transports

  • TCP+TLS
  • WebSocket+TLS
  • UDP(Aeron)
  • RDMA

Polyglot

Clone this wiki locally