public 20100828 j_ruby_kaigi_10things_jror_with_javaee
DESCRIPTION
2010年8月28日のJRuby会議で話したプレゼン資料です。 ・ JRuby + Jax-WS ・ JRuby + JMS ・ JRuby + EJB の話をしています。TRANSCRIPT
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
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/
3
Also I am a writer[How to develop JRuby on Rails]
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
5
6
エンタープライズ・システムで大事なことを
考えてみた
Think about what important things for enterprise system
http://www.flickr.com/photos/marcinmoga/4572263486/in/photostream/
7
エンタープライズシステムは多くのシステムが
連動して動く
Lots of systems are connecting each other on enterprise
systems
8
JRoRシステムも繋がらないと
JRoR system must connect with
other systemshttp://www.flickr.com/photos/yngrich/8828592/
9http://www.flickr.com/photos/marvinkuo/2153147300/
繋がるために3つのJava EE 技術の
力を使う
3 things aboutJava EE
for connecting each other
1. JAX-WS API.2. JMS API.3. EJB.
10
本で書けなかったことにも言及
Mention to what I couldn’t write down on my book
11
about JAX-WS・・・
http://www.flickr.com/photos/shinyai/335249511/
12
空前の SOAP ブーム※エンタープライズシステム限定
The SOAP boom spreadlike wildfire
just only on enterprise system
http://www.flickr.com/photos/usfwssoutheast/4642078354/
13
•SOAP Webサービス実装の安定化
•SOAでレガシー再構築という夢
•SOAPで繋げるクラウド基盤多数
• stabilize SOAP Web Service impl• fantasy of restructuring of legacy system
using SOA• SOAP connect with cloud computing
base
14
Rails+SOAPRailsは、SOAPを捨てた
RubyとXMLの相性が「よい」とはいえない
Rails dump SOAP; not get along with Ruby and XML
REXML
15
+
http://http://www.flickr.com/photos/pinksherbet/3038760752/
16
メリットJAX-WSは扱いやすく、比較的高速
NetBeansなどツールサポートが手厚い
JAX-WS is easy to use, faster to access and have lots of
support tools like NetBeans.
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;
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
19
about JMS・・・
http://www.flickr.com/photos/shinyai/335249511/
20
RailsからMoMを使いたい安定した非同期通信基盤を使いたい
M1・・・・ M2Mn
Message oriented Middleware
Rails other system
want to use MoM from Rails, want to use stable
async-messaging base
21
非同期通信のメリットユーザーにいち早く応答できる
他システム連携が容易
the merit of async-messagingprompt response to users
easy to collaborate other systems
JRoR
othersystems
time
message
22
Rails+非同期通信AP4R、ActiveMessagingなどがあるが、WMQ
など安定した基盤を使いたい
Rails + async-messagingAP4R, ActiveMessaging and so on...
But want to use stable base like WMQ
23
+
http://http://www.flickr.com/photos/pinksherbet/3038760752/
24
メリットJMSをサポートするMoMが多い
トランザクション処理が容易に書ける
ActiveMessagingもJMSをサポート
meritMany MoMs support JMSEasy to develop for transaction functionAlso ActiveMessaging support JMS
EJB/Web Service Container
25
JRoR
Java Application Server
Rails Web App
Mongrel other systems
JMS client
例)メッセージ送信ex) sending messages
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
27
では、メッセージを受け取るには?
http://www.flickr.com/photos/marcinmoga/4240686102/
Then how to receive messages?
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
29
about EJB ・・・
http://www.flickr.com/photos/shinyai/335249511/
29
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?
31
+
http://http://www.flickr.com/photos/pinksherbet/3038760752/
32
メリットXAを使った分散トランザクションが可能
トランザクション処理コードの複雑さが緩和
meritcan develop a distributed transaction system using XA without any complicated messy transaction code
33
典型的な使い方
typical usage
EJB
Java App Server
Rails App M1・・・・ M2Mn
MoM
other system
RDB
34
but,
でも、
35
こうやりたいよね
want to do like this wayJava App Server
M1・・・・ M2Mn
MoM
other systems
RDB
ActionController
ActiveRecord
JMS
same transaction
DataSourceJTA
war
web container
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.
37
Try it!
やってみよう!
38http://www.flickr.com/photos/proimos/4199675334/
failure... orz
失敗
39
理由(調査中)『リソースマネージャが
グローバルトランザクションの外で作業中』
コネクション管理が別なのが原因か
Why?(consumption)“The resource manager is doing work
outside a global transaction”separate connection management
http://http://www.flickr.com/photos/anitakhart/4626206362/
40
conclusion
まとめ
41http://www.flickr.com/photos/marvinkuo/2153147300/
繋がるために3つのJava EE 技術の
力を使おう!
Let’s use Java EEconnecting each other!
42http://www.flickr.com/photos/yngrich/8828592/
大事なのはお互いが繋がること
The most important thing is
“Connecting each other”
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