아파치 쓰리프트 (apache thrift)
TRANSCRIPT
![Page 2: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/2.jpg)
Thrift
Thrift 란 ?
• The Apache Thrift software framework, for scalable cross-language services development
![Page 3: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/3.jpg)
Thrift
Thrift 역사
• 2007 년까지 Facebook 에서 개발 , 이후에는 아파치 소프트웨어 재단
![Page 4: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/4.jpg)
Thrift
Thrift 와 Protocol Buffer 와 비교
Thrift Protocol Buffer
개발사 Facebook Apache Google
채택사 Facebook, Hadoop (Eco System 관련 )
사용자 많다 보통
지원 대부분 C++,java,python
지원기능 많다 적은편
자료형지원 Map, List, Set 등 지원 지원안함
![Page 5: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/5.jpg)
Thrift
Thrift 설치
• 설치준비 필요환경– https://thrift.apache.org/docs/install/
– Basic requirements• A relatively POSIX-compliant *NIX system• Cygwin or MinGW can be used on Windows (but there are better options, see below)• g++ 4.2• boost 1.53.0• Runtime libraries for lex and yacc might be needed for the compiler.
– Requirements for building from source• GNU build tools:• autoconf 2.65• automake 1.13• libtool 1.5.24• pkg-config autoconf macros (pkg.m4)• lex and yacc (developed primarily with flex and bison)• libssl-dev
– Requirements for building the compiler from source on Windows• Visual Studio C++• Flex and Bison (e.g. the WinFlexBison package)...
![Page 6: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/6.jpg)
Thrift
Thrift 설치
• Thrift 설치환경준비
sudo yum -y updatesudo yum -y groupinstall "Development Tools"sudo yum install -y wget
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gztar xvf autoconf-2.69.tar.gzcd autoconf-2.69./configure --prefix=/usrmakesudo make installcd ..
wget http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gztar xvf automake-1.14.tar.gzcd automake-1.14./configure --prefix=/usrmakesudo make installcd ..
https://thrift.apache.org/docs/install/centos
![Page 7: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/7.jpg)
Thrift
Thrift 설치
• Thrift 설치환경준비
wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gztar xvf bison-2.5.1.tar.gzcd bison-2.5.1./configure --prefix=/usrmakesudo make installcd ..
git clone https://git-wip-us.apache.org/repos/asf/thrift.gitcd thrift./bootstrap.sh./configure --with-lua=nomakesudo make install
![Page 8: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/8.jpg)
Thrift
Thrift 프로젝트 생성
• Ant 다운로드 및 설치– yum -y install ant이후 , Thrift 압축해제 디렉터리에 가서 다음 명령어를 실행함– ant -Dproxy.enabled=1 -Dproxy.host=myproxyhost -Dproxy.user=thriftuser -
Dproxy.pass=topsecret
https://thrift.apache.org/lib/java
![Page 9: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/9.jpg)
Thrift
Thrift 프로젝트 생성
• Thrift 코드 Import 시 의존라이브러리– 아래 의존라이브러리를 다운로드후 ‘ add JAR’ 하여 프로젝트에 포함
– slf4j• http://www.slf4j.org/dist/• slf4j-api-1.7.9.jar
– Libthrift• http://repo1.maven.org/maven2/org/apache/thrift/libthrift/0.9.2/• libthrift-0.9.2.jar
![Page 10: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/10.jpg)
Thrift
Thrift Interface Description Language
• Thrift I.D.L 작성– 공통으로 사용할 인터페이스를 정의합니다 .namespace java tutorial.arithmetic.gen namespace js tutorial.arithmetic.gen //Namespace setting for each programming language typedef i64 longtypedef i32 intservice ArithmeticService { // defines simple arithmetic servicelong add(1:int num1, 2:int num2),long multiply(1:int num1, 2:int num2),}
Thrift –gen java calc.thrift 로 java 코드 생성시 파일명과 서비스명이됨
< calc.thrift >
https://thrift.apache.org/docs/idl
![Page 11: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/11.jpg)
Thrift
Thrift I.D.L 에 기반한 인터페이스 코드 생성
• IDL 기반 언어별 Thrift 인터페이스 생성
• Node.JS 예 – gen-node 에 생성됨
• JAVA 예
$ thrift --gen java calc.thrift
thrift --gen <language> <Thrift filename>
thrift --gen js:node calc.thrift
![Page 12: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/12.jpg)
Thrift
Thrift 서버
• Java 인터페이스 코드생성– # thrift --gen java calc.thrift– ‘namespace java tutorial.arithmetic.gen’ 에 따라 디렉터리 생성됨– Tutorial 디렉터리를 자바 프로젝트 폴더로 옮김
![Page 13: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/13.jpg)
Thrift
Thrift 서버
public class Server { private void start() { try { TServerSocket serverTransport = new TServerSocket(7911); ArithmeticService.Processor processor = new ArithmeticService.Processor(new ArithmeticServiceImpl()); TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport). processor(processor)); System.out.println("Starting server on port 7911 ..."); server.serve(); } catch (TTransportException e) { e.printStackTrace(); } } public static void main(String[] args) { Server srv = new Server(); srv.start(); } }
![Page 14: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/14.jpg)
Thrift
Thrift 서버
public class ArithmeticServiceImpl implements ArithmeticService.Iface{ public long add(int num1, int num2) throws TException { return num1 + num2; }
public long multiply(int num1, int num2) throws TException { return num1 * num2; }}
https://github.com/Flipkart/phantom/tree/master/sample-thrift-proxy/src/main/java/thrift
![Page 15: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/15.jpg)
Thrift
Thrift 클라이언트
• Node.JS 에서 thrift 스크립트로 부터 Node 인터페이스 생성– npm install thrift – thrift –gen js.node calc.thrift
https://thrift.apache.org/tutorial/nodejs
![Page 16: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/16.jpg)
Thrift
Thrift 클라이언트
router.get('/test', function (req, res, next) { var thrift = require('thrift'); var Calculator = require('../gen-nodejs/ArithmeticService'); var ttypes = require('../gen-nodejs/calc_types');
var connection = thrift.createConnection("localhost", 7911);
var client = thrift.createClient(Calculator, connection); connection.on('error', function (err) { console.error(err); }); client.multiply(100,200, function(err, response) { console.log("multiply : 100*100=" + response); });
client.add(100,200, function(err, response) { console.log("add : 100+200=" + response); }); res.send('hello world');});
![Page 17: 아파치 쓰리프트 (Apache Thrift)](https://reader031.vdocuments.mx/reader031/viewer/2022012316/55cee4f0bb61ebba108b45f4/html5/thumbnails/17.jpg)
Thrift
Thrift 테스트결과
• 서버실행 (Java)– 제공자 관점
• 클라이언트 실행 (Node.JS) – 요청자 관점