Vril - The Power of the Comming Race - Sir Edward Bulwer-Lytton
Whats comming JMS 2.0
-
Upload
oracle-fusion-middleware -
Category
Technology
-
view
6.609 -
download
8
description
Transcript of Whats comming JMS 2.0
1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JSR 343 : What’s Coming Java Message Service 2.0 日本オラクル株式会社 シニア Java エバンジェリスト 寺田 佳央
3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
以下の事項は、弊社の一般的な製品の方向性に関する概要を説明するものです。また、情報提供を唯一の目的とするものであり、いかなる契約にも組み込むことはできません。以下の事項は、マテリアルやコード、機能を提供することをコミットメント(確約)するものではないため、購買決定を行う際の判断材料になさらないで下さい。オラクル製品に関して記載されている機能の開発、リリースおよび時期については、弊社の裁量により決定されます。
OracleとJavaは、Oracle Corporation 及びその子会社、関連会社の米国及びその他の国における登録商標です。文中の社名、商品名等は各社の商標または登録商標である場合があります。
4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Program Agenda
• はじめに – JMS の復習
• JMS 2.0 の新機能 • まとめ • 参考情報
5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5
はじめに
6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
つながり
8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Messaging とは
• ソフトウェアやアプリケーションをつなぐための手段 – 類似例:電子メール(人と人とをつなぐ手段)
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Point To Point (1対1)
送信 受信 プロデューサー メッセージプロバイダ コンシュマー
11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
パブリッシャ メッセージプロバイダ
サブスクライバ
サブスクライバ
サブスクライバ
Publish / Subscribe (1対多)
サブスクライブ パブリッシュ
12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java SE/EE 環境で利用可能
Java SE
JMS API
Java EE EJB JMS API
※ Application Client Container も利用可能
13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java SE Appilcation
Application Client
Container Message
Driven Bean
開発生産性(低) 開発者の考慮が必要
開発生産性(高) コンテナが豊富な機能を実装
アプリケーション実装方法の比較
14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMS 参照実装 Open MQ
15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
http://mq.java.net/
※ GlassFish の Enterprise Platform 版にバンドル
16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Open MQ(メッセージ・プロバイダ) の起動
GlassFish> ./imqbrokerd -name “myBroker”!
[27/3/2012:16:10:28 JST] !
======================================================== !
Open Message Queue 4.5.2!
Oracle バージョン: 4.5.2 (Build 2-d)!
!
… (中略)!
!
[27/3/2012:16:10:29 JST] [B1039]: ブローカ ! “[email protected]:7676” の準備ができました。
メッセージプロバイダが OpenMQ の場合
17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージプロバイダの送信先(宛先)一覧
GlassFish> ./imqcmd list dst !
ユーザ名: admin!
パスワード: [admin]!
指定されたブローカ上のすべての送信先のリスト:!
--------------------------------------------------------------- !
名前 タイプ 状態 プロデューサ コンシューマ Msgs !Total ワイルドカード Total ワイルドカード カウント リモート UnAck Avg Size!--------------------------------------------------------------- !
mq.sys.dmq キュー 実行中 0 – 0 – 1 0 0 996.0!送信先のリストに成功しました。
18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java SE 環境の 実装
Java SE
JMS API
19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMS アプリケーション on Java SE • メッセージ・プロバイダに接続
– 直接アドレス指定、JNDIルックアップ • キューへの接続 • メッセージ作成 • メッセージ送信
JMS クライアント メッセージプロバイダ
宛先のキュー名
20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMS アプリケーション ‒ 接続
public class Sender {!
public static void main(String[] args) throws JMSException {!
com.sun.messaging.ConnectionFactory connectionFactory = !
new com.sun.messaging.ConnectionFactory();!
connectionFactory.setProperty(com.sun.messaging.!
ConnectionConfiguration.imqAddressList,!
"mq://127.0.0.1:7676");!
javax.jms.QueueConnection queueConnection = !
connectionFactory.createQueueConnection("admin", "admin");!
…… (続く)!
21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMS アプリケーション on Java SE 環境 public class Sender {!
……(続き)!
javax.jms.QueueSession queueSession = queueConnection.!
createQueueSession (false, Session.AUTO_ACKNOWLEDGE);!
javax.jms.Queue smsQueue = queueSession. !
createQueue("sample_queue");!
javax.jms.MessageProducer producer = queueSession. !
createSender(smsQueue);!
Message msg = queueSession.createTextMessage(“メッセージ送信”);!
producer.send(msg);!
queueConnection.close();}}
22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java SE 環境で利用した場合の課題
• 接続ファクトリを自身で生成 – MQプロバイダと密結合 – MQプロバイダ・依存クラスを利用 – 可読性・保守性・移植性の低下
• コネクション・プールの利用が不可能 – コネクションの再利用が困難 – 大量リクエストでMQプロバイダへ高負荷を掛ける可能性あり
• トランザクション処理を自身で実装
23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
コンテナ上で動作 Java SE App/EJB JMS API
24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージプロバイダ
JNDI 名前空間 接続
ファクトリ
jms/MyFactory
メッセージ・プロバイダ設定 • アプリケーション・サーバの設定
– 接続ファクトリ – 宛先
管理者 宛先
jms/MyQueue
宛先のキュー名
25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
GlassFishの管理コンソール 接続ファクトリの設定 (コネクション・ファクトリ)
GlassFish の場合 管理ツールから接続ファクトリの設定
メッセージプロバイダ
26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
GlassFish の場合 管理ツールから送信先(宛先)の設定
メッセージプロバイダ
宛先のキュー名
27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMS アプリケーション on コンテナ • アプリケーション・クライアント・コンテナ • EJB コンテナ
JNDI 名前空間 接続
ファクトリ 宛先
JMS クライアント
リソース・ インジェクション jms/MyFactory jms/MyQueue
クライアントはJNDI経由で 論理的に接続
メッセージプロバイダ
宛先のキュー名 開発者
28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
アプリケーション・ クライアント・ コンテナの実装
Java SE App Client JMS API
29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
リソースのインジェクション
public class OrderSender {!
@Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
public static void main(String argv[]) throws !
JMSException{ !
…… (続く) !
30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージの送信 public static void main(String argv[]) throws JMSException{ !
Connection con = connectionFactory.createConnection();!
Session session = !
con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage();!
message.setText(“メッセージ送信”);!
prod.send(message);!
session.close();!
con.close();!
}!
31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージの受信 public class MyMessageListener implements MessageListener{!
@Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
!
public void onMessage(Message message){!
System.out.println("Message received: " !
+ ((TextMessage)message).getText();!
}!
…… (続く)
32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージの受信 …… (続き)!
public static void main(String[] args){!
Connection connection = !
connectionFactory.createConnection();!
Session session = !
connection.createSession(false,Session.AUTO_ACKNOWLEDGE);!
MessageConsumer consumer = session.createConsumer(queue);!
consumer.setMessageListener(new MyMessageListener());!
connection.start(); !
} }!
33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
EJB コンテナ (MDB) の実装
Java SE EJB JMS API
34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java EE EJB MDB
Message Driven Bean とは
• EJBコンテナで実行されるコンシュマー(受信者) – プロデューサ(送信者)として実装することも可能
• コードの大幅な簡略化 – マルチスレッド – セキュリティ – トランザクション
• EJB による AOP開発 – Interceptor – PostConstruct, Predestroy
35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
MDBによるメッセージ受信 @MessageDriven(mappedName = "jms/mySampleQueue”)!
public class ReceiverMDB implements MessageListener {!
public void onMessage(Message message) {!
try {!
TextMessage msg = (TextMessage) message;!
System.out.println(“Message received:" !
+ msg.getText());!
} catch (JMSException jmse) {!
jmse.printStackTrace();!
}}} トランザクション、セキュリティ、 Interceptor 等も利用可能
36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 5
JMS 2.0の 新機能
37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java Message Service 2.0 (JSR 343)
• 2011年3月:全開一致承認 • Java EE 7 仕様の一部として提供 • エキスパート・グループによって作業中 • コミュニティ活動への参加の呼びかけ
– jms-spec.java.net – メーリング・リストへの参加、コメント Spec Lead
Nigel Deakin
38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
パブリック・レビュー ドラフト提出(計画)
アーリー・ドラフト提出(予定)
Java EE 7ファイナル リリース(予定)
JMS 2.0 ロードマップ
Q1 2012
Q2 2013
Q4 2011
39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
http://jms-spec.java.net
40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMS 2.0 の変更点のポイント
42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
• 新規簡易 API を提供 • 例外の実装方法が変更 • 既存 API に対する改善 • CDI を利用した冗長コードの排除
43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存のMDB : メッセージ受信 in Java EE
@MessageDriven(mappedName = "jms/mySampleQueue”)!
public class ReceiverMDB implements MessageListener {!
public void onMessage(Message message) {!
TextMessage msg = (TextMessage) message;!
System.out.println(“受信したメッセージ:" !
+ msg.getText());!
}!
}
受信用コード実装は簡単
44 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存のMDB : メッセージ送信 in Java EE @Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
!
public void sendMessage(String text){!
Connection con = connectionFactory.createConnection();!
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage(text);!
message.setText(message);!
prod.send(message);!
con.close();
メッセージ送信の実装は面倒
45 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存の問題点: メッセージ送信 in Java EE @Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
!
public void sendMessage(String text){!
Connection con = connectionFactory.createConnection();!
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage(text);!
message.setText(message);!
prod.send(message);!
con.close();
単なるメッセージ送信に 中間オブジェクトが必要
46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存の問題点: メッセージ送信 in Java EE @Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
!
public void sendMessage(String text){!
Connection con = connectionFactory.createConnection();!
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage(text);!
message.setText(message);!
prod.send(message);!
con.close();
定型的なコード
47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
新規簡易 API MessagingContext を提供
javax.jms.MessagingContext インタフェース MessagingContext
Connection Session
MessageProducer MessageConsumer
• 別々のクラスを1つに統合 – Connection – Session – MessageProducer – MessageConsumer
48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
MessagingContext の利用例
MessagingContext context = conFactory.createMessagingContext();!
TextMessage textMsg = context.createTextMessage(message);!
context.send(queue, textMsg);!
!
MessagingContext context = conFactory.!
createMessagingContext(AUTO_ACKNOWLEDGE);!
MessageListener mListener = new MyMsgListener();!
context.setMessageListener(queue, mListener);!
メッセージ送信
メッセージ受信
49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存の問題点: メッセージ送信 in Java EE public void sendMessage(String text){!
Connection con = null;!
try{!
con = connectionFactory.createConnection();!
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage(text);!
message.setText(message);!
prod.send(message);!
}finally{!
con.close();!
}
使用後コネクションの クローズが必要
50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java SE 7 の try-with-resource に対応
AutoCloseable による実装 (close()の実装が不要) ! public void sendMessage(String text){!
try(MessagingContext ctx = cFactory.createContext()){!
TextMessage message = session.createTextMessage(text);!
message.sendText(outQueue,message);!
}!
}!
51 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存の問題点: メッセージ送信 in Java EE public void sendMessage(String text){!
try{!
……// 送信処理!
prod.send(message);!
}catch(JMSException jmse){!
// 例外処理!
}finally{!
try{!
if(con != null) con.close();!
}catch (JMSException jmse2){!
// 例外処理!
}!
}}
例外処理の実装が 必要
52 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
例外の実装方法が変更 チェック例外から非チェック例外へ
過去の例外クラス 今後の例外クラス JMSException JMSRuntimeException
TransactionRolledBackException TransactionRolledBackRuntimeException
IllegalStateException IllegalStateRuntimeException!
InvalidDestinationException IllegalDestinationRuntimeException!
InvalidSelectorException InvalidSelectorRuntimeException
MessageFormatException MessageFormatRuntimeException
53 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
例外の実装方法が変更 例外処理の実装は不要 (RuntimeException) public void sendMessage(String text){!
……// 送信処理!
prod.send(message);!
}
54 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
既存の問題点: メッセージ送信 in Java EE @Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
!
public void sendMessage(String text){!
Connection con = connectionFactory.createConnection();!
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage(text);!
message.setText(message);!
prod.send(message);!
con.close();
冗長的な引数
55 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
javax.jms.Connection に対する改善
セッション作成方法の簡易化 • 今まで
– Connection#createSession( transacted, deliveryMode ) • 今後
– Java SE で利用可能な新規メソッド • Connection#createSession( sessionMode )
– Java EE で利用可能な新規メソッド • Connection#createSession()
56 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
CDIアノテーションを使用した依存性注入
MessagingContext に対する注入 @Inject!
private MessagingContext context;
• リクエスト・スコープ • リクエスト毎にコネクションを生成 • 処理終了時に自動的にコネクション切断
57 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
CDIアノテーションを使用した依存性注入
MessagingContext に対する注入 @Inject!
@JMSConnectionFactory(“jms/MyConFactory”)!
private MessagingContext context;
• JNDI ルックアップでコンテナの接続ファクトリを使用 – コネクション・プール等を利用可能
• JNDI 名を未指定時、システムのデフォルト使用
58 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
CDIアノテーションを使用した依存性注入
MessagingContext に対する注入 @Inject!
@JMSConnectionFactory(“jms/MyConFactory”) !
@JMSPasswordCredential(userName=“admin”,password=“admin”)!
private MessagingContext context;
• ユーザ名・パスワードを指定
59 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
CDIアノテーションを使用した依存性注入
MessagingContext に対する注入 @Inject!
@JMSConnectionFactory(“jms/MyConFactory”) !
@JMSSessionMode(MessagingContext.AUTO_ACKNOWLEDGE)!
private MessagingContext context;
• セッション・モードを指定 – SESSION_TRANSACTED, CLIENT_ACKNOWLEDGE,
AUTO_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE – (デフォルト:AUTO_ACKNOWLEDGE)
60 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
CDIアノテーションを使用した依存性注入
MessagingContext に対する注入 @Inject!
@JMSConnectionFactory(“jms/MyConFactory”) !
@JMSAutoStart(false)!
private MessagingContext context;
• JMSContext#setAutoStart(false)と同等
• コンシューマ作成時JMSContextで使用する接続を自動的に起動
61 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
62 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java EE 6 までのメッセージ送信 @Resource( mappedName="jms/MyConnectionFactory” )!
private static ConnectionFactory connectionFactory; !
@Resource( mappedName="jms/mySampleQueue” )!
private static Queue queue;!
!
public void sendMessage(String text){!
Connection con = connectionFactory.createConnection();!
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);!
MessageProducer prod = session.createProducer(queue);!
TextMessage message = session.createTextMessage(text);!
message.setText(message);!
prod.send(message);!
con.close();
63 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Java EE 7 におけるメッセージ送信 @Inject!
@JMSConnectionFactory(“jms/MyConFactory”) !
private MessagingContext context;!
!
@Resource(mappedName = “jms/queue”)!
private Queue queue;!
!
public void sendNewMessage(String msg){!
context.send(queue, msg);!
}
64 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
• マルチテナンシーのサポート – リソース生成用メタデータ
• 議論中の内容 – http://java.net/jira/browse/JMS_SPEC-57
• Java EE 7 仕様中で定義 – EE.5.17.4、EE.5.17.5(JMSでない)
65 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージプロバイダ
JNDI 名前空間 接続
ファクトリ
jms/MyFactory
今までの実装・運用方法 ‒ 手順 1 • アプリケーション・サーバの設定
– 接続ファクトリ – 宛先
管理者 宛先
jms/MyQueue
宛先のキュー名
66 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
今までの実装・運用方法 ‒ 手順 2 • 設定済のリソースをルックアップ
JNDI 名前空間 接続
ファクトリ 宛先
JMS クライアント
リソース・ インジェクション jms/MyFactory jms/MyQueue
クライアントはJNDI経由で 論理的に接続
メッセージプロバイダ
宛先のキュー名 開発者
67 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
現状ではマルチテナンシー対応が困難
テナント A 管理者が接続ファクトリ、宛先を設定 開発者は管理者が設定したJNDI 名をコードに反映
テナント B 管理者が接続ファクトリ、宛先を設定 開発者は管理者が設定したJNDI 名をコードに反映
テナント C 管理者が接続ファクトリ、宛先を設定 開発者は管理者が設定したJNDI 名をコードに反映
68 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
メッセージプロバイダ
実現したい事 • アプリケーション上で必要なリソースを設定可能
管理者 (配備者)
テナントB宛先
JNDI 名前空間 接続
ファクトリ 宛先
接続 ファクトリ 宛先
テナントA宛先
69 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
新規メタデータを提供 ‒ 接続ファクトリ
@JMSConnectionFactoryDefinition @JMSConnectionFactoryDefinition(!
name=“java:app/MyJMSFactory” ,!
resoureType=“javax.jms.QueueConnectionFactory” ,!
clientId=“foo” ,!
resourceAdapter=“jmsra” ,!
initialPoolSize=5 ,!
maxPoolSize=15!
) ※ 同等の XML 設定を提供
70 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
新規メタデータを提供 ‒ 宛先
@JMSDestinationDefinition @JMSDestinationDefinition(!
name=“java:app/MyQueue” ,!
resoureType=“javax.jms.Queue” ,!
resourceAdapter=“jmsra” ,!
destinationName=“myQueue”,!
tenantIsolation=“ISOLATED or SHARED”!
) ※ 同等の XML 設定を提供
71 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
• 開発容易性の大幅な向上 • Java EE 7 のテーマをサポート
– クラウド対応 – マルチ・テナンシー
• その他
72 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
参考情報 • JSR 343
– http://jcp.org/en/jsr/detail?id=343 • JMS 2.0 の仕様
– http://java.net/projects/jms-spec – http://java.net/projects/jms-spec/downloads
• JMS-Spec JIRA – http://java.net/jira/browse/JMS_SPEC
• OpenMQ – http://mq.java.net/
73 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
Russia 17–18 April 2012
India 3–4 May 2012
San Francisco September 30–October 4, 2012
74 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
75 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
76 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
• 直接オブジェクト内容送信 • 永続サブスクリプションの簡易化 • JMSプロバイダ、アプリケーションサーバ間インタフェース定義 • MDBの設定改善 • 遅延配信 • サーバからの非同期ACKを受信するメッセージ送信 • JMSDeliveryCount の必須化 • トピックの階層構造化 • 特定トピックのサブスクリプションに対する複数のコンシュマー • バッチ配信
77 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
直接オブジェクトの内容を送信可能
• メッセージの作成は不要 – producer#send(String text); – producer#send(Serializable object);
• 制限事項 – メッセージ・プロパティの設定は不可 – BytesMessage での使用は非推奨 – receive() メソッドでの同様操作は検討中(不明確)
78 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
永続サブスクリプションの実装の簡易化
• 今までの永続サブスクリプションの識別方法 – {clientId, subscriptionName}
• 今後、永続サブスクリプションで clientId は省略可能 • EJB 3.2 より MDB を使用する場合、コンテナがデフォルトのサブスクリプション名を自動生成
79 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMSプロバイダ・アプリケーションサーバ間のインタフェースを定義
• 目的: – 任意のプロバイダと任意のアプリケーションサーバの動作を保証
• 対応: – Java EE Connector Architecture (JCA) を必須で提供
80 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
MDB の改善 (提案中)
• JSR 342 (EJB 3.2) へ提案中 • MDB における標準的な設定方法
– 宛先(キュー、トピック)の JNDI 名 (メタデータ中) – 接続の JNDI 名 (メタデータ中) – クライアント ID – 永続サブスクリプション名
81 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
MDB の改善 (提案中) ‒ 宛先の定義
• アノテーションによる設定 @MessageDriven(messageDestinationLookup=“jms/queue”)!
public class MyMDB implements MessageListener{!
……!
}
82 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
MDB の改善 (提案中) ‒ 接続の定義
• アノテーションによる設定 @MessageDriven(connectionFactoryLookup=“jms/myCF”)!
public class MyMDB implements MessageListener{!
……!
}
83 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
MDB の改善 (提案中) ‒ 永続サブスクリプションの定義 • アノテーションによる設定
@MessageDriven(activationConfig = {!
@ActivationConfigProperty(!
propertyName=“subscriptionDurability”, propertyValue="Durable"),!
@ActivationConfigProperty(!
propertyName="clientId",propertyValue="MyMDB"),!
@ActivationConfigProperty(!
propertyName="subscriptionName",propertyValue="MySub”)!
})!
public class MyMDB implements MessageListener{!
……!
84 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
遅延配信
• メッセージ配信におけるスケジューリングが可能 • MessageProducer に対する新規追加メソッド
– Public void setDeliveryDelay (long deliveryDelay) • 生成したメッセージを、メッセージプロバイダ上で、コンシュマーに配信するまで保持する時間をミリ秒で指定
85 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
サーバからの非同期応答を受け取る メッセージ配信 • メッセージを送信後、応答をサーバから受け取るまで処理をブロックせずに即座に返す
• 応答を受信した際、代わりに非同期コールバックを呼び出す
producer.send(message, new AcknowledgeListener(){!
public void onAcknowledge(Message message){!
// ACK に対する処理!
}!
});!
86 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
JMSXDeliveryCount が必須に
• JMS 1.1 では JMSXDeliveryCount のプロパティは 省略可能 – 使用した場合:
• メッセージを受信した際、JMSプロバイダが設定を実施 • メッセージが配信された回数を設定(最初の配信も含め) • 初回配信時:1、次回配信時:2
• JMS 2.0 では必須
87 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
トピックの階層構造 ‒ 詳細検討中
• トピックを階層構造に配置可能 – STOCK.NASDAQ.TECH.ORCL – STOCK.NASDAQ.TECH.GOOG – STOCK.NASDAQ.TECH.ADBE – STOCK.NYSE.TECH.HPQ
• コンシュマーはワイルドカードでサブスクライブ可能 – STOCK.*.TECH.* – STOCK.NASDAQ.TECH.*
88 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
特定トピックのサブスクリプションに対する複数のコンシュマー • スケーラビリティの向上を目的 • トピックのサブスクリプションからのメッセージをスケーラブルに処理可能 – マルチスレッド – マルチ JavaVM
• 永続サブスクリプションのAPIには変更無し • 非永続サブスクリプション用の新規 API MessageConsumermessageConsumer =!
session.createSharedConsumer(topic,sharedSubscriptionName);!
89 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
バッチ配信
• メッセージをバッチで非同期配信 • MessageConsumer に対する新規追加メソッド void setBatchMessageListener(!
BatchMessageListener listener,int batchSize,long batchTimeOut)!
• 新規 BatchMessageListener リスナー void onMessages(Message[]messages)!
• ACK もバッチで送信 • JMSプロバイダもしくはアプリケーションの効果的利用
90 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8
91 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8