简体   繁体   English

如何从Javascript调用MessagePack RPC服务?

[英]How to invoke a MessagePack RPC service from Javascript?

I've got this simple Java server process running as a MessagePack RPC service. 我已经将此简单的Java服务器进程作为MessagePack RPC服务运行。 I want to invoke the hello() service from Javascript, not Java, but have yet to find an example on how to achieve it. 我想从Java而不是Java调用hello()服务,但尚未找到有关如何实现它的示例。 There does not appear to be a RPC implementation for Javascript on the MessagePack site. 在MessagePack站点上,似乎没有针对Javascript的RPC实现。

import org.msgpack.rpc.Server;
import org.msgpack.rpc.loop.EventLoop;

public class ServerApp {
    public String hello() {
        return "OK";
    }

    public static void main(String[] args) throws Exception {
        EventLoop loop = EventLoop.defaultEventLoop();

        Server svr = new Server();
        svr.serve(new ServerApp()); 
        svr.listen(1985);

        loop.join();
    }
}

UPDATE Found a Javascript RPC client for MessagePack here... UPDATE在这里找到了MessagePack的Javascript RPC客户端...

https://github.com/nori0428/msgpack.rpc.js https://github.com/nori0428/msgpack.rpc.js

这些似乎是用于MsgPack RPC的(非官方)JavaScript绑定-它们可能有效(没有尝试过): https : //github.com/nori0428/msgpack.rpc.js

There is a Javascript implementation (and one for node.js as well). 有一个Javascript实现(还有一个针对node.js的实现)。

https://github.com/msgpack/msgpack-javascript https://github.com/msgpack/msgpack-javascript

Documentation is missing however. 但是缺少文档。 You'll need to use the following script: 您需要使用以下脚本:

https://raw.github.com/msgpack/msgpack-javascript/master/msgpack.js https://raw.github.com/msgpack/msgpack-javascript/master/msgpack.js

Take a look through that and you'll see the functions that are available. 看一遍,您将看到可用的功能。 There is also the test directory. 还有测试目录。 Look at the .html files in there for examples of use. 查看其中的.html文件以获取使用示例。

https://github.com/msgpack/msgpack-javascript/tree/master/test https://github.com/msgpack/msgpack-javascript/tree/master/test

Does it actually work? 它真的有效吗? No idea, I haven't tried it myself. 不知道,我自己还没有尝试过。 Let us know how it goes. 让我们知道怎么回事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM