基于Java的JMS框架,它使用websockets作为传输

时间:2015-06-29 07:58:06

标签: java websocket jms

我试图在基于java的客户端和服务器之间实现双向通信,主协议是JMS。但是由于客户端驻留的管理Intranet限制,因此无法进行入站连接。主要思想是将JMS包装成类似HTTP的东西。我选择了Websockets。我找到的唯一解决方案是OpenMQ。它支持这一点。还有更好的解决方案吗?

感谢。

1 个答案:

答案 0 :(得分:1)

JMS is a way different way of communication compared to websockets. Briefly :

  • Websockets are an implementation of sockets for the Web. A socket is a connection that is made between 2 peers. The connection is on hold, while the peers exchange messages. The connection is maintained during the whole communication and it is closed after the communication has ended.
  • JMS is a Java standard/API for sending messages between 2 or more clients. However, it is differently structured. In JMS, there is an entity called message broker, where messages are sent, stored and then retrieved by the clients. So, this approach can be a distributed environment.

So, JMS is a different approach to Websockets, since JMS is "stateless" and optionally asynchronous, while websockets are stateful and synchronous.

Thus, I think you should not make a choice between those 2, considering only the firewall limitation, but you should be more focused on the context of the 2 approaches, deciding which one is more suitable for your case.

If you believe that JMS is a better solution, then you should alter the firewall rules, so that the port used for JMS (by default 1099) is allowed with specific security limitations. Otherwise, you can use websockets, accepting the performance limitation of synchronous communication.

There is also the approach of integrating websockets with JMS, that is captured by openMQ and other frameworks. However, I do not know what the implications in performance will be compared to simple JMS, and I think that this solution should be chosen, only if we talk about a web application.

Additional Comment

There is also the capability of using HTTP tuneling over JMS. Thus, you will not have to use websockets. You will still use JMS, but there will be a servlet that will be receiving HTTP requests and redirecting them to the JMS service. This has also been implemented in openMQ, as you can see in the tutorial. In this way, you ovveride the firewall restriction, without adding the complexity of websockets.