项目作者: calebman

项目描述 :
云函数
高级语言: Java
项目地址: git://github.com/calebman/cloud-func.git
创建时间: 2018-12-13T10:09:06Z
项目社区:https://github.com/calebman/cloud-func

开源协议:MIT License

下载


cloud-func

云函数

啥意思

通过socket连接的方式调用java的方法,实现远程调用,是不是还挺有意思的!

如何使用

  1. // 先写一个供远程调用的函数,然后使用注解标识它,比如这样
  2. @Register("fun")
  3. public class RemoteFunc {
  4. @Register
  5. public String add(String a, String b) {
  6. return a + b;
  7. }
  8. }
  9. // 实例化云函数服务,然后在云函数服务类中注册这个函数
  10. public class ServerTest {
  11. public static void main(String[] args) {
  12. RemoteFunc remoteFunc = new RemoteFunc();
  13. CftpServer cftpServer = new CftpServer();
  14. // 注册
  15. cftpServer.getCftpContext().registerObj(remoteFunc);
  16. // 启动云函数
  17. cftpServer.start();
  18. }
  19. }

怎么远程调用呢

  1. 每个类会有自己的groupName与methodName标识,调用遵循
  1. groupName methodName param1 param2
  1. 测试一下
  1. # 启动云函数服务 见单元测试ServerTest.java
  2. # telnet连接云函数服务 默认端口8080
  3. telnet localhost 8080
  4. # 输入指令
  5. cftp help