这篇文章主要介绍hadoop中rpc的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
超过十余年行业经验,技术领先,服务至上的经营模式,全靠网络和口碑获得客户,为自己降低成本,也就是为客户降低成本。到目前业务范围包括了:成都网站设计、做网站,成都网站推广,成都网站优化,整体网络托管,微信小程序,微信开发,成都app软件开发公司,同时也可以让客户的网站和网络营销和我们一样获得订单和生意!
[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的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!