这篇文章主要介绍hadoop中rpc的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
[root@localhost hadoop-2.4.1]# service network restart启动网卡
windos 端的UserLoginController
package cn.itcast.bigdata.hadoop.rpc;
import java.io.IOException;
import java.net.InetSocketAddress;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
public class UserLoginController {
public static void main(String[] args) throws Exception {//先启动服务器端
Configuration conf = new Configuration();
LoginServiceInterface loginServiceImpl = RPC.getProxy(LoginServiceInterface.class, 1L, new InetSocketAddress("192.168.88.155", 10000), conf);
String res = loginServiceImpl.login("angelababy", "123");
System.out.println(res);
}
}
package cn.itcast.bigdata.hadoop.rpc;
public interface LoginServiceInterface {
public static final long versionID = 1L;
public String login(String username,String password);
}
linux端的
package cn.itcast.bigdata.hadoop.rpc;
public class LoginServiceImpl implements LoginServiceInterface{
@Override
public String login(String username, String password) {
return username + "logged in successfully!";
}
}
package cn.itcast.bigdata.hadoop.rpc;
public interface LoginServiceInterface {
public static final long versionID = 1L;
public String login(String username,String password);
}
package cn.itcast.bigdata.hadoop.rpc;
import java.io.IOException;
import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ipc.RPC.Builder;
import org.apache.hadoop.ipc.RPC.Server;
public class ServerStarter {
public static void main(String[] args) throws HadoopIllegalArgumentException, IOException {//先启动服务器端的
Configuration conf = new Configuration();
Builder builder = new RPC.Builder(conf);
builder.setInstance(new LoginServiceImpl()).setBindAddress("192.168.88.155").setPort(10000).setProtocol(LoginServiceInterface.class);
Server server = builder.build();
server.start();
}
}
以上是“hadoop中rpc的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。