Several options for Java remote communication (the difference between RPC,WEBSERVICE,RMI,JMS)

Source: Internet
Author: User
Tags soap wsdl

RPC (Remote Procedure call Protocol)

RPC uses the C/S method, uses the HTTP protocol, sends the request to the server, waits for the server to return the result. This request consists of a set of parameters and a set of text, usually in the form of "Classname.methodname". The advantage is cross-language cross-platform, c-side, s-side has greater independence, the disadvantage is that the object is not supported, the compiler can not check the error, only at run time check.

Web Service

Web Service provides services based on web containers, the underlying use of the HTTP protocol, similar to a remote service provider, such as the weather Forecast service, to provide weather forecasts for local clients, is a request response mechanism, cross-system cross-platform. is to provide services out through a servlet.

First the client is from the server to the WebService WSDL, and at the same time the client claims that a proxy class is responsible for the proxy class with WebService

Server for request and response when a data (in XML format) is encapsulated in a SOAP-formatted stream to the server, a process object is generated and the SOAP packet that receives the request is parsed, and the thing is processed, Soap the results of this calculation after processing is finished

Packaging, and then the package as a response sent to the client proxy class, in the same way, the proxy class also parses the SOAP packet, followed by subsequent operations. This is a running process for webservice.

A WEB service is broadly divided into 5 levels:

1. HTTP Transport Channel

2. Data format FOR XML

3. SOAP Encapsulation Format

4. How WSDL is described

5. UDDI UDDI is a directory service that enterprises can use to register and search for WebServices

RMI (Remote Method invocation)

RMI uses stubs and skeletons to communicate with remote objects (remotely object). The stub acts as the client proxy for the remote object and has the same remote interface as the remote object, and the call to the remote object is actually done by invoking the object's client proxy object stub, through which RMI is like it works locally, uses the TCP/IP protocol, The client directly invokes some methods on the service side. The advantage is the strong type, the compile time can check the error, the disadvantage is only based on the Java language, the client and the server tightly coupled.

JMS (Java Messaging Service)

JMS is a Java messaging service that allows asynchronous message transmission between JMS clients through the JMS service. JMS supports two message models: Point-to-Point and Publish/subscribe (Pub/sub), the point-to-point and publish-subscribe models.

The difference and connection of several people

1. RPC and RMI

(1) RPC is a cross-language, and RMI only supports Java.

(2) RMI invokes a remote object method that allows methods to return Java objects and basic data types, whereas RPC does not support the concept of objects, and the messages passed to the RPC service are represented by external data representations (External data representation, XDR) language, which is abstract The difference between the byte-order class and the data type structure. Only data types defined by XDR can be passed, and RMI is a Java RPC object-oriented approach.

(3) On a method call, in RMI, the remote interface causes each remote method to have a method signature. If a method executes on the server, but no matching signature is added to the remote interface, the new method cannot be called by the RMI client.

In RPC, when a request arrives at the RPC server, the request contains a set of parameters and a literal value, usually in the form of a "classname.methodname". This indicates to the RPC server that the requested method is in the class "ClassName", which is called "MethodName". The RPC server then searches for classes and methods that match it and takes it as input to the type of the method parameter. The parameter type here is matched to the type in the RPC request. Once the match is successful, the method is called, and the result is encoded and returned to the client side.

2. JMS and RMI

With JMS services, objects are physically asynchronously moved directly from one JVM on the network to another (the message notification mechanism)

The RMI object is bound to the local JVM, and only the function arguments and return values are transmitted over the network (the request answering mechanism).

RMI is generally synchronous, that is, when the client calls a method of the server, you need to wait until the other side of the return to continue to execute the client side, the process calls the local method feels the same, this is a feature of RMI.

JMS is generally just a point to send a message to message Server, which generally does not care who uses this message.

Therefore, the application of general RMI is tightly coupled, and JMS applications are relatively loosely coupled applications.

3, WebService and RMI

RMI is the delivery of serializable Java objects on the TCP protocol, which can only be used on Java virtual machines, binding languages, both the client and server must be Java

WebService does not have this limitation, WebService is to pass an XML text file on the HTTP protocol, regardless of language and platform

4. WebService and JMS

WebService focuses on remote service invocation, and JMS focuses on information exchange.

In most cases webservice is a direct interaction between two systems (Consumer <--> Producer), and in most cases JMS is a tripartite system interaction (Consumer <-Broker, Producer). Of course, JMS can also implement Request-response mode of communication, as long as the consumer or producer one side of the broker.

JMS can do asynchronous calls to completely isolate the client and service provider, to withstand traffic peaks; WebService services are typically synchronous calls, require complex object transformations, and now json,rest are good HTTP schema schemes compared to soap, for example, E-commerce Distributed system, there are payment systems and business systems, payment systems responsible for user payments, in the bank after the payment needs to inform the various business systems, then this time, can either use synchronous or asynchronous, the benefits of using async can withstand the temporary traffic peak, or can deal with slow consumers. )

------------

Personally, the most essential difference is that webservice near real-time communication, while MQ is usually delayed communication. What do you mean? Because WebService is actually the local server program calls the method on the remote server, the interaction between the two, the request needs to wait for the requested server to respond, the other end will be the action, that is, if you request the service server shut down, or interrupted, Then you certainly will not have the answer, your request even if it is lost. And MQ is the equivalent of a middleware I send a request must first be communicated to the Message Queuing component, and then by the Message Queuing component to another server to request, have a response and then return to the original requestor, because the MessageQueue component will persist the message on the local, So even if the sudden crash, the request message is not lost. For example, we have a complex request to generate a report, to generate a report can be quite complicated, so for a few minutes, then we certainly can not wait there, this time using MQ, according to the request report to the requirements of MQ, wait until the receiver processing return, I will receive notification, so it is better. Common MQ components include MSMQ, Apache ACTIVEMQ, and some open source MQ.

--------------

JMS is a message specification on the Java platform. The general JMS message is not an XML, but a Java object, and it is clear that JMS does not consider heterogeneous systems, and frankly, JMS does not consider things that are not java. But fortunately, most of the JMS provider (that is, the various implementations of JMS) solve the heterogeneous problem. It's different than WebService's cross-platform.

Several options for Java remote communication (the difference between RPC,WEBSERVICE,RMI,JMS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.