JAVA Remote communication mechanism

Source: Internet
Author: User
Tags soap

In a distributed service framework, one of the most fundamental issues is how remote services communicate, and there are many technologies in the Java domain that enable remote communication, such as RMI, MINA, ESB, Burlap, Hessian, SOAP, EJB, and JMS, What is the relationship between these nouns, and what is the rationale behind them, to understand these are the basic knowledge of implementing a distributed service framework, and if there is a high performance requirement, then it is necessary to understand the mechanisms behind these technologies, and in this blog we will look into the future, We welcome you to provide more information on the technology and principles of remote communication.

Basic principle
To realize the communication between network machines, first of all to see the basic principles of computer network communication, at the bottom level to see, network communication needs to do is to transfer the flow from one computer to another computer, based on the transmission protocol and network IO to achieve, wherein the transport protocol is more famous HTTP, TCP, UDP and so on, HTTP, TCP, UDP are based on the concept of socket for a certain type of application of the extension of the transport Protocol, network IO, mainly bio, NIO, Aio three ways, all distributed application communication based on this principle is realized, just for the application of ease of use, Various languages often offer application-level protocols that are more accessible to applications.

Application-level protocols
Remote service communication, the need to achieve the goal is to make a request on one computer, another machine after receiving the request for processing and return the results to the request side, which will have such as one way request, synchronous request, asynchronous request and so on, according to network communication principle, What needs to be done is to convert the request into a stream and transfer it to the far end via the transfer Protocol, and the remote computer is processed after the requested stream has been received, and the result is converted to a stream after processing, and returned to the caller via the transport protocol.
The principle is this, but for the convenience of application, the industry has introduced a lot of application-level protocols based on this principle, so that people can not go directly to operate such a low level of things, usually application-grade remote communication protocol will provide:
1, in order to avoid direct flow operation so troublesome, provide a more easy-to-use or fit the language of the standard transmission format;
2, the realization of network communication mechanism, is for you to complete the transfer format into a stream, through some kind of transmission protocol to the remote computer, the remote computer after receiving the stream into a transmission format, and to store or in some way notify the remote computer.
So when learning about application-level remote communication protocols, we can learn with these questions:
1. What is the standard format for transmission?
2. How do I convert a request to a streamed stream?
3, how to receive and process the flow?
4. What is the transmission protocol?
However, the application-level remote communication protocol does not make much improvement on the transport protocol, mainly in the flow operation, let the application layer generation flow and processing flow of the process to more closely conform to the language or standards used, as for the transport protocol is usually optional, in the Java domain is well-known: RMI, XML-RPC , Binary-rpc, SOAP, CORBA, JMS, to see specifically the application-level protocols for these remote communications:
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Rmi
RMI is a typical Java custom Remote communication protocol, we know that in a single VM, we can directly invoke the Java object instance to achieve communication, then in the remote communication, if you can also follow this way is of course the best, This remote communication mechanism became RPC (remote Procedure call), and RMI was born to this goal.
Consider the principle of a complete remote communication process based on RMI:
1, the client initiates the request, requests the stub class which transmits to the RMI client;
2, the stub class will request the interface, methods, parameters and other information to serialize;
3, based on the socket to transfer the serialized stream to the server side;
4, the server side received the stream and forwarded to the corresponding Skelton class;
5. The Skelton class invokes the actual processing class after deserializing the requested information;
6. After processing, the result is returned to the Skelton class;
7, Skelton class will result serialization, through the socket will be circulated to the client stub;
8. The stub is deserialized after it receives the stream and returns the deserialized Java object to the caller.
See jboss-remoting for a better illustration of this process:

Follow the principles to answer a few questions before learning the application-level protocol:
1. What is the standard format for transmission?
Is the Java Objectstream.
2. How do I convert a request to a streamed stream?
Converts the requested Java object information into a stream based on the Java serialization mechanism.
3, how to receive and process the flow?
According to the protocol used to start the corresponding listening port, when there is a stream into the system based on the Java serialization mechanism to deserialize the stream, and according to the RMI protocol to obtain the corresponding processing object information, call and processing, the finished result is also based on the Java serialization mechanism to return.
4. What is the transmission protocol?
Socket.
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Xml-rpc
XML-RPC is also a remote invocation protocol similar to RMI, which differs from RMI in that it defines the requested information in a standard XML format (the requested object, method, parameter, etc.), and what is the benefit of being able to use it when communicating across languages.
Take a look at a remote communication process for the XML-RPC protocol:
1, the client initiates the request, according to the XML-RPC protocol to fill the request information;
2. After filling, the XML is transformed into a stream and transmitted through the transmission protocol.
3, received in the received stream after the conversion to XML, according to the XML-RPC protocol to obtain the requested information and processing;
4. After processing, the results are written in XML and returned in accordance with the XML-RPC protocol.
The above process is illustrated:

To answer the question:
1. What is the standard format for transmission?
XML in standard format.
2. How do I convert a request to a streamed stream?
Converts XML into a stream.
3, how to receive and process the flow?
Gets the requested stream through the listening port, translates to XML, and obtains the requested information according to the protocol, processes it and returns the result to the XML.
4. What is the transmission protocol?
Http.
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Binary-rpc
Binary-rpc look at the name to know and Xml-rpc is similar, the difference is only in the transmission of the standard format from XML to binary format.
To answer the question:
1. What is the standard format for transmission?
A binary file in standard format.
2. How do I convert a request to a streamed stream?
Converts binary format files to streams.
3, how to receive and process the flow?
Gets the requested stream through the listening port, translates into a binary file, obtains the requested information according to the protocol, processes it, and returns the result to the XML.
4. What is the transmission protocol?
Http.
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Soap
Soap is originally simple Object Access Protocol, is a distributed environment, lightweight, XML-based information exchange protocol, you can think of soap is an advanced version of XML RPC, the principle of the two are identical, are http+xml, Unlike the XML specification, which is defined only by the two, soap is also the service invocation protocol standard adopted by WebService, so it is not elaborated here.
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Corba
Common Object Request Broker Architecture (Common object request Broker [Scheduler] program architecture) is a set of criteria for defining a "distributed Object System", by the OMG (Object Menagement Group) As the initiator and standard-setting unit. The purpose of CORBA is to define a set of protocols that can interact with each other, regardless of the language in which they are written, regardless of the machine or operating system they run on.
CORBA seems to me to be a SOA-like architecture, covering the optional remote communication protocol, but it can not be included in the communication protocol here, and CORBA Basic elimination, coupled with the CORBA also do not understand, here will not be elaborated.
--------------------------------------------------------------------------------------------------------------- -----------------------------------
Jms
JMS, is the implementation of the Java field of remote communication means and methods, based on the JMS implementation of remote communication and RPC is different, although the effect of RPC can be done, but because it is not defined from the protocol level, so we do not think that JMS is an RPC protocol, but it is really a remote communication protocol, In other language systems there are similar JMS things, you can unify this kind of mechanism called the message mechanism, and the message mechanism, usually high concurrency, distributed domain recommended a communication mechanism, the main problem here is fault tolerance (see the Erlang thesis in detail).
Consider the process of a remote communication in JMS:
1. The client translates the request into a message that complies with the JMS provisions;
2. Put the message into the JMS queue or topic through the JMS API;
3. If it is a JMS queue, the corresponding target Queue in the send, such as topic, is sent to the JMS queue subscribed to this topic.
4, the processing side through the rotation JMS Queue, to obtain the message, after receiving the message according to the JMS protocol to parse the message and processing.
Answer the question:
1. What is the standard format for transmission?
The message specified by JMS.
2. How do I convert a request to a streamed stream?
Put the parameter information in the message.
3, how to receive and process the flow?
Rotation a JMS queue to receive a message, receive it for processing, and still send or multicast in the queue as a message after processing is complete.
4. What is the transmission protocol?
Unlimited.
JMS is also one of the common methods of implementing remote asynchronous calls.

JAVA Remote communication mechanism

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.