RPC (Remote Procedure Call Protocol)
RPC uses C/S mode, adopts http protocol, sends requests to the server, and waits for the server to return the result. The request includes a parameter set and a text set, usually of the form "classname.methodname". The advantage is that it is cross-language and cross-platform, and the C-side and S-side have greater independence. The disadvantage is that it does not support objects and errors cannot be checked in the compiler, but can only be checked at runtime.
Web Service
The services provided by Web Service are based on web containers. The bottom layer uses the http protocol. It is similar to a remote service provider, such as weather forecast services, which are provided to clients in various places. Weather forecast is a request response mechanism that is cross-system and cross-platform. It is through a servlet to provide services.
First, the client sends the WSDL from the server to the WebService, and at the same time claims a proxy class (Proxy Class) on the client. This proxy class is responsible for conducting Request and Response with the WebService
When a When the data (in XML format) is encapsulated into a SOAP format data stream and sent to the server, a process object will be generated and the SOAP packet received by the Request will be parsed, and then the thing will be processed. After the processing is completed, the process object will be processed. The calculation result is packaged in SOAP
, and then the package is sent to the client's proxy class (Proxy Class) as a Response. Similarly, the proxy class also parses the SOAP package and performs subsequent operations. . This is a running process of WebService.
Web Service is generally divided into 5 levels:
1. Http transmission channel
2. XML data format
3 . SOAP encapsulation format
4. WSDL description method
5. UDDI UDDI is a directory service that enterprises can use to register and search Webservices
RMI (Remote Method Invocation)
RMI uses stubs and skeletons to communicate with remote objects. The stub acts as the client proxy of the remote object and has the same remote interface as the remote object. The call to the remote object is actually completed by calling the client proxy object stub of the object. Through this mechanism, RMI works as if it is a local job. TCP/IP protocol, the client directly calls some methods on the server. The advantage is that it is strongly typed and errors can be checked during compilation. The disadvantage is that it can only be based on JAVA language and the client and server are tightly coupled.
JMS (Java Messaging Service)
JMS is a Java messaging service. JMS clients can transmit asynchronous messages through the JMS service. JMS supports two message models: Point-to-Point (P2P) and Publish/Subscribe (Pub/Sub), namely point-to-point and publish-subscribe models.
The differences and connections between them
1. RPC and RMI
(1) RPC is cross-language, while RMI only supports Java.
(2) RMI calls remote object methods, allowing methods to return Java objects and basic data types, while RPC does not support the concept of objects. The messages transmitted to the RPC service are represented by external data (External Data Representation, XDR ) language representation that abstracts the differences between endian classes and data type structures. Only data types defined by XDR can be passed. It can be said that RMI is an object-oriented Java RPC.
(3) In terms of method invocation, in RMI, the remote interface enables each remote method to have a method signature. If a method is executed on the server, but no matching signature is added to the remote interface, then the new method cannot be called by the RMI client.
In RPC, when a request arrives at the RPC server, the request contains a parameter set and a text value, usually in the form of "classname.methodname". This indicates to the RPC server that the requested method is in the class named "methodname". The RPC server then searches for a matching class and method and uses it as input for that method parameter type. The parameter type here matches the type in the RPC request. Once the match is successful, this method is called and the result is encoded and returned to the client.
2. JMS and RMI
Using JMS service, objects are physically and asynchronously moved directly from a JVM on the network to another JVM (a message notification mechanism)
The RMI object is bound in the local JVM, and only the function parameters and return values ??are transmitted through the network (it is a request response mechanism).
RMI is generally synchronous, that is to say, when the client calls a method of the Server, it needs to wait until the other party returns before it can continue to execute the client. This process feels the same as calling a local method. , which is also a feature of RMI.
JMS generally just sends a Message to the Message Server from one point. After sending it, it generally does not care who uses the message.
So, generally RMI applications are tightly coupled, while JMS applications are relatively loosely coupled.
3. Webservice and RMI
RMI transfers serializable java objects over the tcp protocol. It can only be used on the java virtual machine to bind languages, clients and services. The client must be java
Webservice does not have this restriction. Webservice transmits xml text files over 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 lt; --gt; Producer), while in most cases jms is a three-party system interaction (Consumer lt; - Broker -gt; Producer) ). Of course, JMS can also implement request-response mode communication, as long as either the Consumer or the Producer also serves as the broker.
JMS can achieve asynchronous calls that completely isolate the client and service provider, and can withstand traffic peaks; WebService services are usually called synchronously and require complex object conversion. Compared with SOAP, now JSON, rest They are all good HTTP architecture solutions; (For example, in a distributed e-commerce system, there are payment systems and business systems. The payment system is responsible for user payments. After the user pays at the bank, it needs to notify each business system. Then at this time , you can use either synchronous or asynchronous. The advantage of using asynchronous is that it can resist the temporary traffic peak of the website, or cope with slow consumers)
JMS is a message specification on the java platform. Generally, a jms message is not an xml, but a java object. Obviously, jms does not consider heterogeneous systems. To put it bluntly, JMS does not consider non-java things. But fortunately, most jms providers (that is, various implementation products of JMS) have solved the heterogeneous problem. Compared with the cross-platform of WebService, each has its own merits.