简体   繁体   English

用于RabbitMQ的JSON RPC 2.0的Java客户端

[英]Java Client for JSON RPC 2.0 over RabbitMQ

I need to write a Java JSON-RPC client that will communicate over RabbitMQ. 我需要编写一个Java JSON-RPC客户端,该客户端将通过RabbitMQ进行通信。 All the implementations I've found assumed HTTP as the transport, and that won't work for me. 我发现的所有实现都将HTTP作为传输方式,这对我不起作用。 RabbitMQ has it's own RPC client/server, but it's JSON-RPC 1.1, not 2.0. RabbitMQ有自己的RPC客户端/服务器,但它是JSON-RPC 1.1,而不是2.0。

Anyone have any suggestions? 有人有什么建议吗? Thanks. 谢谢。

JSON-RPC is just a communications protocol based on JSON; JSON-RPC只是基于JSON的通信协议; JSON is just some UTF-16 text. JSON只是一些UTF-16文本。 JSON-RPC is therefore transport protocol-agostic (ie: the JSON-RPC specification only concerns itself with the CONTENT of messages). 因此,JSON-RPC是与传输协议兼容的(即:JSON-RPC规范仅涉及消息的内容 )。

A JSON-RPC "webservice" is necessarily transported via HTTP(s). JSON-RPC“ Web服务”必须通过HTTP传输。 However, a JSON-RPC "server" can use almost any transport (eg: raw TCP, SMTP, etc). 但是,JSON-RPC“服务器”几乎可以使用任何传输方式(例如:原始TCP,SMTP等)。

You could have a simple line-oriented (process a message when you see a newline) TCP server, and as long as the request is JSON-RPC formatted, and the reply is JSON-RPC formatted, then that is a JSON-RPC "server". 您可以有一个简单的面向行的(当您看到换行符时处理一条消息)TCP服务器,只要请求是JSON-RPC格式的,并且答复是JSON-RPC格式的,那么这就是JSON-RPC“服务器”。 If your transport protocol has the ability to receive and send UCS-2/UTF-16 then you can implement JSON-RPC over it. 如果您的传输协议具有接收和发送UCS-2 / UTF-16的能力,则可以在其上实现JSON-RPC。

Folks have already implemented JSON-RPC over "comet", websockets, webRTC, etc. 人们已经通过“ comet”,websockets,webRTC等实现了JSON-RPC。

Some parts of the JSON-RPC 2.0 protocol are easier to implement over certain transports. JSON-RPC 2.0协议的某些部分在某些传输方式上更易于实现。 For example, if your transport doesn't have simultaneous bi-directional communication (eg: HTTP or HTTPs) then you can only implement a simplified version of the "notification" message. 例如,如果您的传输没有同步的双向通信(例如:HTTP或HTTPs),那么您只能实现“通知”消息的简化版本。 Instead of the "server" sending notification messages to the client whenever it pleases, either it piggy-backs "notification" messages on RPC-style replies (perhaps using "batch" messages), or the client itself "polls" the server for "notification" messages. 代替“服务器”在需要时向客户端发送通知消息的方式,它要么在RPC样式的回复中piggy带“通知”消息(也许使用“批处理”消息),要么客户端本身“轮询”服务器以获取“通知”消息。

RabbitMQ has a plugin called web-stomp which implements websockets so that web browsers can communicate with RabbitMQ using JavaScript. RabbitMQ有一个名为web-stomp的插件,该插件实现websocket,以便网络浏览器可以使用JavaScript与RabbitMQ进行通信。 If your target client is a web-browser and you don't need asynchronous notification support, you could easily send JSON-RPC messages over the websockets polyfill provided by web-stomp. 如果目标客户端是Web浏览器, 并且不需要异步通知支持,则 可以轻松地通过web-stomp提供的websockets polyfill发送JSON-RPC消息。

If your client language can already talk to RabbitMQ natively, then you simply encode the UTF-16 into something publishable by RabbitMQ and and decode them on the other side. 如果您的客户语言已经可以与RabbitMQ进行本地对话,则只需将UTF-16编码为RabbitMQ可以发布的内容,然后在另一端对其进行解码。

EDIT: Of course, websockets are asynchronous, and you can implement proper "notification" style messages over them. 编辑:当然,websocket 异步的,您可以在它们之上实现适当的“通知”样式消息。

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

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