public 20100828 j_ruby_kaigi_10things_jror_with_javaee

43
1 10 things : How to enhance the power of JRoR using Java EE technology 橋本 吉治 http://www.flickr.com/photos/shinyai/335249511/ Japan Java User Group @hasssie JRubyKaigi2010 28th Aug HASHIMOTO Yoshiharu

Upload: yoshiharu-hashimoto

Post on 30-Jun-2015

916 views

Category:

Technology


1 download

DESCRIPTION

2010年8月28日のJRuby会議で話したプレゼン資料です。 ・ JRuby + Jax-WS ・ JRuby + JMS ・ JRuby + EJB の話をしています。

TRANSCRIPT

Page 1: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

1

10 things : How to enhance the power of JRoRusing Java EE technology

橋本 吉治

http://www.flickr.com/photos/shinyai/335249511/

Japan Java User Group@hasssie

JRubyKaigi2010 28th Aug

HASHIMOTO Yoshiharu

Page 2: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

2

自己紹介who am I

Rubyを愛するJava開発者

JJUG / 卓球.rb

某SIer勤務

Java guy loves Ruby

a member of Japan Java User Groups,TableTennis.rb

working at a big IT service companyhttp://www.flickr.com/photos/vs/186075406/

Page 3: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

3

Also I am a writer[How to develop JRuby on Rails]

プレゼンター
プレゼンテーションのノート
■ 企業の情報システムで使うアプリケーション」を前提にしている点が大きな特長で、そのためのミドルウェアやクラスタリング技術の導入、あるいはJava EEシステムとの連携方法など、エンタープライズでのRoR利用をより現実解に近い形に落とし込んで解説しています。 ★ 詳細 http://www.seshop.com/product/detail/12020/ ■ 購入 http://www.amazon.co.jp/JRuby-Rails%E3%82%B7%E3%82%B9%E3%83%86%E3%83%A0%E6%A7%8B%E7%AF%89%E5%85%A5%E9%96%80-DB-Magazine-SELECTION/dp/4798121444
Page 4: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

1. Java App Server2. JAX-WS API3. JMS API4. EJB5. JDBC driver6. JMX7. Spring Framework8. Java IDE9. Java OSS library10. Java build tool like Ant

4

Page 5: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

5

Page 6: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

6

エンタープライズ・システムで大事なことを

考えてみた

Think about what important things for enterprise system

http://www.flickr.com/photos/marcinmoga/4572263486/in/photostream/

Page 7: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

7

エンタープライズシステムは多くのシステムが

連動して動く

Lots of systems are connecting each other on enterprise

systems

Page 8: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

8

JRoRシステムも繋がらないと

JRoR system must connect with

other systemshttp://www.flickr.com/photos/yngrich/8828592/

Page 9: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

9http://www.flickr.com/photos/marvinkuo/2153147300/

繋がるために3つのJava EE 技術の

力を使う

3 things aboutJava EE

for connecting each other

Page 10: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

1. JAX-WS API.2. JMS API.3. EJB.

10

本で書けなかったことにも言及

Mention to what I couldn’t write down on my book

Page 11: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

11

about JAX-WS・・・

http://www.flickr.com/photos/shinyai/335249511/

Page 12: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

12

空前の SOAP ブーム※エンタープライズシステム限定

The SOAP boom spreadlike wildfire

just only on enterprise system

http://www.flickr.com/photos/usfwssoutheast/4642078354/

Page 13: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

13

•SOAP Webサービス実装の安定化

•SOAでレガシー再構築という夢

•SOAPで繋げるクラウド基盤多数

• stabilize SOAP Web Service impl• fantasy of restructuring of legacy system

using SOA• SOAP connect with cloud computing

base

Page 14: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

14

Rails+SOAPRailsは、SOAPを捨てた

RubyとXMLの相性が「よい」とはいえない

Rails dump SOAP; not get along with Ruby and XML

REXML

Page 15: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

15

http://http://www.flickr.com/photos/pinksherbet/3038760752/

Page 16: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

16

メリットJAX-WSは扱いやすく、比較的高速

NetBeansなどツールサポートが手厚い

JAX-WS is easy to use, faster to access and have lots of

support tools like NetBeans.

Page 17: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

17

require 'java'require 'jar/UsersManagerWSClient'import ‘ws.client.UsersManagerService’class UsersManager

def initialize@service = UsersManagerService.new.get_users_manager_port

end

def find(user_id); transform(@service.find(user_id.to_s)); end

privatedef transform(jobj)# Java オブジェクト⇒ Rubyオブジェクトの変換

endend

STEP1: WSDLからコード生成してjarに固めるSTEP2: 下記のコードを書く

Step1: generate from WSDL and pack into jarStep2: write code as follows;

Page 18: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

18

Step1: XMLスキーマを設計Step2: xjcコマンドを使ってJavaクラスの生成Step3:下記のコードを書く

Step1: Design XML schemaStep2: generate Java class using xjc commandStep3: write code above

def unmarshalctx = JAXBContext.newInstance("net.pkg.class") um = ctx.createUnmarshaller() gbc = (GeneratedBindingClass) um.unmarshal(file) xmlVal = gbc.getXMLValueOfInterest() end

Page 19: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

19

about JMS・・・

http://www.flickr.com/photos/shinyai/335249511/

Page 20: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

20

RailsからMoMを使いたい安定した非同期通信基盤を使いたい

M1・・・・ M2Mn

Message oriented Middleware

Rails other system

want to use MoM from Rails, want to use stable

async-messaging base

Page 21: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

21

非同期通信のメリットユーザーにいち早く応答できる

他システム連携が容易

the merit of async-messagingprompt response to users

easy to collaborate other systems

JRoR

othersystems

time

message

Page 22: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

22

Rails+非同期通信AP4R、ActiveMessagingなどがあるが、WMQ

など安定した基盤を使いたい

Rails + async-messagingAP4R, ActiveMessaging and so on...

But want to use stable base like WMQ

Page 23: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

23

http://http://www.flickr.com/photos/pinksherbet/3038760752/

Page 24: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

24

メリットJMSをサポートするMoMが多い

トランザクション処理が容易に書ける

ActiveMessagingもJMSをサポート

meritMany MoMs support JMSEasy to develop for transaction functionAlso ActiveMessaging support JMS

Page 25: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

EJB/Web Service Container

25

JRoR

Java Application Server

Rails Web App

Mongrel other systems

JMS client

例)メッセージ送信ex) sending messages

Page 26: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

26

STEP1.下記のコード or ActiveMessagingを使う

Step1: Use this code above or ActiveMessaging

import javax.jms.Session;import javax.naming.InitialContext;class UsersRegisterdef initialize@context = InitialContext.new

end

def regist(user, ut)begincf =@context .lookup "jms/UsersRegisterQConFactory"que =@context .lookup "jms/UsersRegisterQueue"con = cf.create_queue_connectionqs =con.create_queue_session(false,Session.AUTO_ACKNOWLEDGE

)        sender = qs.create_sender(que)            msg = qs.create_text_messagemsg.set_text(create_msg(user))sender.send(txt);

rescue

Page 27: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

27

では、メッセージを受け取るには?

http://www.flickr.com/photos/marcinmoga/4240686102/

Then how to receive messages?

Page 28: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

28

MDBで受信、RESTでJRoRへ

EJB/Web Service ContainerJRoR

Session Bean

Java Application Server

Rails Web App

Message-driven Bean

Web Service

Mongrel other systems

SOAP client

REST I/F

MDB receive messages and use REST to JRoR

Page 29: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

29

about EJB ・・・

http://www.flickr.com/photos/shinyai/335249511/

29

Page 30: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

30

Railsから2pcを使いたい!

Rails App

other sytem2

process1‐1process1

process1‐2

other sytem1

2 phase commit = prepare(1) + commit(2)

want to use 2pc from Rails?

Page 31: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

31

http://http://www.flickr.com/photos/pinksherbet/3038760752/

Page 32: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

32

メリットXAを使った分散トランザクションが可能

トランザクション処理コードの複雑さが緩和

meritcan develop a distributed transaction system using XA without any complicated messy transaction code

Page 33: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

33

典型的な使い方

typical usage

EJB 

Java App Server

Rails App M1・・・・ M2Mn

MoM

other system

RDB

Page 34: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

34

but,

でも、

Page 35: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

35

こうやりたいよね

want to do like this wayJava App Server

M1・・・・ M2Mn

MoM

other systems

RDB

ActionController

ActiveRecord

JMS

same transaction

DataSourceJTA

war

web container

Page 36: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

36

# POST /users# POST /users.xmldef createut = InitialContext.new.lookup "UserTransaction“@user = User.new(params[:user])respond_to do |format|beginut.begin # transaction [email protected]!                          # persist to RDBsend_queue(@user)           # send queue

・・・

ut.commit;                            # transaction commitendrescueut.rollback # transaction rollback

・・・

send queue with user transaction.

Page 37: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

37

Try it!

やってみよう!

Page 38: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

38http://www.flickr.com/photos/proimos/4199675334/

failure... orz

失敗

Page 39: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

39

理由(調査中)『リソースマネージャが

グローバルトランザクションの外で作業中』

コネクション管理が別なのが原因か

Why?(consumption)“The resource manager is doing work

outside a global transaction”separate connection management

http://http://www.flickr.com/photos/anitakhart/4626206362/

Page 40: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

40

conclusion

まとめ

Page 41: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

41http://www.flickr.com/photos/marvinkuo/2153147300/

繋がるために3つのJava EE 技術の

力を使おう!

Let’s use Java EEconnecting each other!

Page 42: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

42http://www.flickr.com/photos/yngrich/8828592/

大事なのはお互いが繋がること

The most important thing is

“Connecting each other”

Page 43: Public 20100828 j_ruby_kaigi_10things_jror_with_javaee

43

10 things : How to enhance the power of JRoRusing Java EE technology

橋本 吉治

http://www.flickr.com/photos/shinyai/335249511/

Japan Java User Group@hasssie

JRubyKaigi2010 28th Aug

HASHIMOTO Yoshiharu