In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "RPC mechanism in Hadoop". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the RPC mechanism in Hadoop.
RPC (Remote Procedure Call)-remote procedure call protocol, which is a protocol that requests services from remote computer programs over a network without knowing the underlying network technology. The RPC protocol assumes the existence of certain transport protocols, such as TCP or UDP, to carry information data between communication programs. In the OSI network communication model, RPC spans the transport layer and the application layer. RPC makes it easier to develop applications, including web-based distributed multiprograms.
RPC adopts client / server mode. The requester is a client and the service provider is a server. First, the client invocation process sends a call message with process parameters to the service process, and then waits for the reply message. On the server side, the process stays asleep until the calling message arrives. When a call message arrives, the server obtains the process parameters, calculates the result, sends the reply message, and then waits for the next call message. Finally, the client invokes the process to receive the reply message, obtains the process result, and then calls execution to proceed.
The entire architecture of Hadoop is built on top of RPC (see org.apache.hadoop.ipc package)
Use RPC: (build a Hadoop pseudo-distributed virtual machine (server side), and the local Windows connects to the virtual machine (client side)
1. Define RPC protocol interface LoginProtocol (Hadoop RPC protocol is usually a Java interface). RPC protocol interface is the communication interface between Client and Server, which defines the interface provided by Server. The LoginProtocol interface declares a login () method. It should be noted that all custom RPC protocol interfaces in Hadoop have a field called versionID, which describes the version information of the protocol. This RPC protocol interface is co-owned by Client/Server. Both Server and Client must have the same LoginProtocol.class file.
Public interface LoginProtocol {public static final long versionID = 1L; public String login (String username, String password);}
two。 On the server side, LoginProtocolImpl implements RPC protocol interface (LoginProtocol)
Public class LoginProtocolImpl implements LoginProtocol {@ Override public String login (String username, String password) {return "wellcome" + username;}}
3. RPC Server is constructed and started on the Server side. "192.168.8.101" is the ip address of the Server, and the Server side listens on the "1234" port.
Public static void main (String [] args) throws HadoopIllegalArgumentException IOException {/ / set 4 required parameters: / / setBindAddress ("192.168.8.101"): IP address / / setPort (1234) on the Server side: Port / / setProtocol (LoginProtocol.class): class object / / setInstance (new LoginProtocolImpl ()) of the setRPC protocol interface: instance of the implementation class of the RPC protocol interface Server server = new RPC.Builder (new Configuration ()) .setBindAddress ("192.168.101") ). SetPort (1234) .setProtocol (LoginProtocol.class) .setInstance (new LoginProtocolImpl ()) .build () Server.start ();}}
4. The RPC client is constructed on the Client side, and the client RPC proxy object (proxy) is constructed by using the RPC class static method getProxy (). The login () method of the RPC proxy object (proxy) is called to send the RPC request. "192.168.8.101" is the ip address of Server, and "1234" is the listening port on Server.
Public class LoginClient {public static void main (String [] args) throws IOException {/ / getProxy () Parameter: / / LoginProtocol.class: class object of RPC protocol interface / / 1L: version information of RPC protocol interface (versionID) / / new InetSocketAddress ("192.168.101", 1234): IP address and port / / conf: Configuration instance LoginProtocol proxy = RPC.getProxy (LoginProtocol.class, 1L, new InetSocketAddress ("192.168.101", 1234)) New Configuration () String result = proxy.login ("rpc", "xxx"); System.out.println (result);}}
Next, a magical scene happened!
Console output of local Windows:
Wellcome rpc
Does the local Windows have an implementation of the LoginProtocol interface?
No!
Thank you for your reading, the above is the content of "RPC mechanism in Hadoop". After the study of this article, I believe you have a deeper understanding of the RPC mechanism in Hadoop, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.