- 浏览: 2540018 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Thrift(2)RMI Strategy Sample
RMI is short for remote method invocation. It is easy to use it in java world.
But it is complex to go through the firewall. And the language is limited to java.
From other's blogs, we can use RMI easily like this
Interface class first:
package com.sillycat.easytalker.plugins.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IHello extends Remote {
public String helloWorld() throws RemoteException;
public String sayHelloToSomeBody(String someBodyName)
throws RemoteException;
}
Implementation class like this:
package com.sillycat.easytalker.plugins.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements IHello {
private static final long serialVersionUID = 6318519261707859826L;
public HelloImpl() throws RemoteException {
}
public String helloWorld() throws RemoteException {
return "Hello World!";
}
public String sayHelloToSomeBody(String someBodyName)
throws RemoteException {
return "Hello, nice to meet you, " + someBodyName + "!";
}
}
Server side to register the Interface and implementation:
package com.sillycat.easytalker.plugins.rmi;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class RMIServer {
public static void main(String[] args) {
try {
IHello rhello = new HelloImpl();
LocateRegistry.createRegistry(9813);
Naming.bind("//localhost:9813/rhello", rhello);
System.out.println(">>>>>INFO:Remote IHello Binding Success!");
} catch (RemoteException e) {
e.printStackTrace();
} catch (AlreadyBoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
Client side to call the server side:
package com.sillycat.easytalker.plugins.rmi;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class RMIClient {
public static void main(String[] args) {
try {
IHello rhello = (IHello) Naming.lookup("//localhost:9813/rhello");
System.out.println(rhello.helloWorld());
System.out.println(rhello.sayHelloToSomeBody("sillycat"));
} catch (NotBoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
For go across the firewall, base on the blog: http://wangse.iteye.com/blog/191797
we can use SMRMISocket.java
1.import java.rmi.server.*;
2.import java.io.*;
3.import java.net.*;
4.public class SMRMISocket extends RMISocketFactory {
5. public Socket createSocket(String host, int port)
6. throws IOException{
7. return new Socket(host,port);
8. }
9. public ServerSocket createServerSocket(int port)
10. throws IOException {
11. if (port == 0)
12. port = 2098;//this port will be random if we did not set it.
13. return new ServerSocket(port);
14. }
15.}
And spring will have easy configuration for this:
<bean id="rmiSearchService" class="org.springframework.remoting.rmi.RmiServiceExporter">
2.<property name="serviceName" value="search"/><!-- service name -->
3.<property name="service" ref="searchService"/>
4.<property name="serviceInterface" value="velcro.searchengine.ISearcher"/>
5.<property name="registryPort" value="2098"/><!-- port -->
6.<property name="servicePort" value="2098"/>><!-- port-->
7.</bean>
But I do not think RMI is a good choice for us, there is easy ways for hessian, phprpc, soap(xfire/cxf/axis2) and so on.
So I just read document about RMI after google it. Just get to know about this knowledge point.
references:
http://gemantic.iteye.com/blog/1199214
http://www.cnblogs.com/birdshover/archive/2010/03/16/1687301.html
http://www.javabloger.com/article/thrift-java-code-example.html
http://www.javabloger.com/article/apache-thrift-architecture.html
http://yangfanchao.iteye.com/blog/1271737
http://thrift.apache.org/docs/idl/
http://thrift.apache.org/docs/types/
http://wangse.iteye.com/blog/191797
RMI is short for remote method invocation. It is easy to use it in java world.
But it is complex to go through the firewall. And the language is limited to java.
From other's blogs, we can use RMI easily like this
Interface class first:
package com.sillycat.easytalker.plugins.rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface IHello extends Remote {
public String helloWorld() throws RemoteException;
public String sayHelloToSomeBody(String someBodyName)
throws RemoteException;
}
Implementation class like this:
package com.sillycat.easytalker.plugins.rmi;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class HelloImpl extends UnicastRemoteObject implements IHello {
private static final long serialVersionUID = 6318519261707859826L;
public HelloImpl() throws RemoteException {
}
public String helloWorld() throws RemoteException {
return "Hello World!";
}
public String sayHelloToSomeBody(String someBodyName)
throws RemoteException {
return "Hello, nice to meet you, " + someBodyName + "!";
}
}
Server side to register the Interface and implementation:
package com.sillycat.easytalker.plugins.rmi;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
public class RMIServer {
public static void main(String[] args) {
try {
IHello rhello = new HelloImpl();
LocateRegistry.createRegistry(9813);
Naming.bind("//localhost:9813/rhello", rhello);
System.out.println(">>>>>INFO:Remote IHello Binding Success!");
} catch (RemoteException e) {
e.printStackTrace();
} catch (AlreadyBoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
Client side to call the server side:
package com.sillycat.easytalker.plugins.rmi;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
public class RMIClient {
public static void main(String[] args) {
try {
IHello rhello = (IHello) Naming.lookup("//localhost:9813/rhello");
System.out.println(rhello.helloWorld());
System.out.println(rhello.sayHelloToSomeBody("sillycat"));
} catch (NotBoundException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
For go across the firewall, base on the blog: http://wangse.iteye.com/blog/191797
we can use SMRMISocket.java
1.import java.rmi.server.*;
2.import java.io.*;
3.import java.net.*;
4.public class SMRMISocket extends RMISocketFactory {
5. public Socket createSocket(String host, int port)
6. throws IOException{
7. return new Socket(host,port);
8. }
9. public ServerSocket createServerSocket(int port)
10. throws IOException {
11. if (port == 0)
12. port = 2098;//this port will be random if we did not set it.
13. return new ServerSocket(port);
14. }
15.}
And spring will have easy configuration for this:
<bean id="rmiSearchService" class="org.springframework.remoting.rmi.RmiServiceExporter">
2.<property name="serviceName" value="search"/><!-- service name -->
3.<property name="service" ref="searchService"/>
4.<property name="serviceInterface" value="velcro.searchengine.ISearcher"/>
5.<property name="registryPort" value="2098"/><!-- port -->
6.<property name="servicePort" value="2098"/>><!-- port-->
7.</bean>
But I do not think RMI is a good choice for us, there is easy ways for hessian, phprpc, soap(xfire/cxf/axis2) and so on.
So I just read document about RMI after google it. Just get to know about this knowledge point.
references:
http://gemantic.iteye.com/blog/1199214
http://www.cnblogs.com/birdshover/archive/2010/03/16/1687301.html
http://www.javabloger.com/article/thrift-java-code-example.html
http://www.javabloger.com/article/apache-thrift-architecture.html
http://yangfanchao.iteye.com/blog/1271737
http://thrift.apache.org/docs/idl/
http://thrift.apache.org/docs/types/
http://wangse.iteye.com/blog/191797
发表评论
-
Update Site will come soon
2021-06-02 04:10 1672I am still keep notes my tech n ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 288Hadoop Docker 2019 Version 3.2. ... -
Nginx and Proxy 2019(1)Nginx Enable Lua and Parse JSON
2019-12-03 04:17 437Nginx and Proxy 2019(1)Nginx En ... -
Data Solution 2019(13)Docker Zeppelin Notebook and Memory Configuration
2019-11-09 07:15 279Data Solution 2019(13)Docker Ze ... -
Data Solution 2019(10)Spark Cluster Solution with Zeppelin
2019-10-29 08:37 243Data Solution 2019(10)Spark Clu ... -
AMAZON Kinesis Firehose 2019(1)Firehose Buffer to S3
2019-10-01 10:15 313AMAZON Kinesis Firehose 2019(1) ... -
Rancher and k8s 2019(3)Clean Installation on CentOS7
2019-09-19 23:25 301Rancher and k8s 2019(3)Clean In ... -
Pacemaker 2019(1)Introduction and Installation on CentOS7
2019-09-11 05:48 333Pacemaker 2019(1)Introduction a ... -
Crontab-UI installation and Introduction
2019-08-30 05:54 442Crontab-UI installation and Int ... -
Spiderkeeper 2019(1)Installation and Introduction
2019-08-29 06:49 493Spiderkeeper 2019(1)Installatio ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 363Supervisor 2019(2)Ubuntu and Mu ... -
Supervisor 2019(1)CentOS 7
2019-08-19 09:33 321Supervisor 2019(1)CentOS 7 Ins ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 365Redis Cluster 2019(3)Redis Clus ... -
Amazon Lambda and Version Limit
2019-08-02 01:42 432Amazon Lambda and Version Limit ... -
MySQL HA Solution 2019(1)Master Slave on MySQL 5.7
2019-07-27 22:26 507MySQL HA Solution 2019(1)Master ... -
RabbitMQ Cluster 2019(2)Cluster HA and Proxy
2019-07-11 12:41 456RabbitMQ Cluster 2019(2)Cluster ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:35 315Running Zeppelin with Nginx Aut ... -
Running Zeppelin with Nginx Authentication
2019-05-25 21:34 316Running Zeppelin with Nginx Aut ... -
ElasticSearch(3)Version Upgrade and Cluster
2019-05-20 05:00 321ElasticSearch(3)Version Upgrade ... -
Jetty Server and Cookie Domain Name
2019-04-28 23:59 389Jetty Server and Cookie Domain ...
相关推荐
在本文中,我们将深入探讨如何使用Java通过Thrift2接口操作HBase数据库。HBase是一个分布式、可扩展的大数据存储系统,它构建于Hadoop之上,支持实时读写。Thrift是一个轻量级的框架,用于跨语言服务开发,允许不同...
Python Thrift2与HBase的交互是大数据领域中常见的操作,尤其在分布式系统中,为了高效地访问HBase存储的数据,开发者通常会采用Thrift2作为通信协议。Thrift是一种跨语言的服务框架,它允许不同编程语言之间的高效...
在本文中,我们将深入探讨如何使用Golang连接到HBase数据库,特别是在最新的Thrift2协议下。Thrift是一种跨语言的服务开发工具,它允许我们定义服务接口,然后自动生成多种编程语言的代码,使得不同语言之间可以进行...
在本示例中,我们将深入探讨如何使用Python通过Thrift2接口来查询HBase。 首先,我们需要理解Thrift2与HBase的关系。Thrift2是Facebook开发的一种接口定义语言(IDL),它可以生成多种编程语言的代码,使得不同语言...
标题“C#使用Thrift2操作HBase数据库”表明我们将讨论如何在C#环境下利用Thrift2库与HBase进行交互,执行基本的数据操作,如添加(Insert)、删除(Delete)、更新(Update)和查询(Select)。 首先,我们需要理解...
2. **服务生成**:Thrift的编译器会根据IDL文件生成服务端和客户端的代码,而RMI则直接基于Java接口创建远程对象和服务端/客户端的桩(stubs)。 3. **服务实现**:开发者需要实现Thrift或RMI定义的服务接口,编写...
Thrift是一种高效的、跨语言的服务框架,最初由Facebook开发,现在是Apache的顶级项目。它提供了强大的代码生成工具,可以从接口定义文件(IDL)生成多种编程语言的客户端和服务端代码,使得不同语言之间可以轻松地...
在本项目中,我们将关注如何使用C#语言通过Thrift2来操作Hbase数据库,实现数据的增、删、改、查(CRUD)功能。 1. **Thrift2与Hbase的交互** Thrift2提供了一种灵活的方式与Hbase进行交互。首先,我们需要在Hbase...
2. **Wireshark配置** - 安装Wireshark:首先确保你的系统上已经安装了Wireshark。如果尚未安装,可以从其官方网站下载适合你操作系统的版本。 - 开启捕获:启动Wireshark,选择合适的网络接口(通常是连接到...
Thrift是Facebook开源的一款高性能、跨语言的服务框架,它的设计目标是高效地在不同编程语言之间进行通信。本文将基于Thrift的Java实现,总结学习过程中的一些关键知识点,旨在帮助理解Thrift的工作原理以及如何在...
阿里云Thrift2连接HBase Demo是一个示例项目,展示了如何使用C#语言通过Thrift2接口与阿里云上的HBase数据库进行交互。这个压缩包包含了一系列必要的代码文件,用于构建一个.NET应用程序,使得开发者能够在.NET环境...
2. **Thrift编译器**:Thrift提供了一个命令行工具,可以根据IDL文件生成不同编程语言的客户端和服务端代码。对于Go语言,它会生成包含接口和协议实现的代码。 3. **服务端实现**:在HBase中,服务端通常是由HBase...
2. **高性能**:Thrift通过高效的序列化和网络协议,实现了低开销、高吞吐量的通信。 3. **易于使用**:通过Thrift IDL,开发者可以定义数据类型和服务接口,Thrift会自动生成相应的代码,大大简化了开发工作。 4....
2. **跨语言支持**:Thrift支持多种编程语言,如Java、C++、Python等,这使得不同语言编写的系统之间可以轻松地进行RPC调用。 3. **强大的IDL支持**:Thrift提供了一个接口定义语言(IDL),用于定义服务接口和服务...
2. **编译服务**:使用Thrift编译器将服务定义文件转换为Java代码,生成服务接口、服务实现类以及客户端的Stub。 3. **Dubbo服务提供者**:将生成的Thrift服务接口和实现类集成到Dubbo服务提供者的项目中,配置服务...
在IT行业中,Thrift是一种高性能、可扩展的跨语言服务开发框架,由Facebook开源,用于构建分布式服务。它通过定义一种中间表示(IDL,接口定义语言)来描述服务,然后自动生成不同编程语言的代码,使得不同语言之间...
《Thrift Castle2t1:探索已知的Thrift源码世界》 在软件开发领域,Thrift是一种高效、跨语言的服务框架,由Facebook于2007年开源。它提供了一种定义数据结构和服务接口的方式,使得不同编程语言之间可以进行无缝...
2. **编译器**:Thrift编译器是整个框架的核心,它将.IDL文件转换为不同目标语言(如Java、Python、C++等)的源代码。在thrift-0.8.0中,你可以找到这个编译工具,通过命令行运行,生成对应的客户端和服务端代码。 ...
2. 添加Thrift依赖:下载并编译Thrift-0.10.0源码,生成C++库。将生成的库文件添加到QT项目的链接器设置中,确保编译时能够找到Thrift的相关库。 3. 生成Thrift代码:根据服务定义(通常是.thrift文件),使用...
2. RPC框架:Thrift通过一个中间层处理服务端和客户端之间的通信,这个中间层负责消息的编码、解码以及错误处理,使得开发者可以专注于业务逻辑,而不是网络通信的细节。 二、Thrift的核心组件 1. IDL(Interface ...