| Interstage Studio プログラマーズガイド |
目次
索引
![]()
|
| 付録A Interstage Application Server V9.0.1以降で動作するJ2EEアプリケーションを開発する | > A.2 EJB2.1のアプリケーションの開発方法 |
Webアプリケーション、EJBアプリケーションまたはJ2EEアプリケーションクライアントからMessage-driven Beanを呼び出す場合、JNDIを使用してJMS Destinationをlookupします。
クライアントアプリケーションの形態に応じて以下のdeployment descriptorにJMS Destinationについて記述を定義する必要があります。
|
クライアントアプリケーションの形態 |
deployment descriptor |
|---|---|
|
WebアプリケーションからJMSメッセージを送信する場合 |
web.xml |
|
EJBアプリケーションからJMSメッセージを送信する場合 |
ejb-jar.xml |
|
J2EEアプリケーションクライアントからJMSメッセージを送信する場合 |
application-client.xml |
<?xml version="1.0" encoding="UTF-8" ?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
・・・
<message-destination-ref>
<description>JMS Destination</description>
<message-destination-ref-name>jms/Topic</message-destination-ref-name>
<message-destination-type>javax.jms.Topic</message-destination-type>
<message-destination-usage>Produces</message-destination-usage>
</message-destination-ref >
</web-app>
deployment descriptorのタグの詳細は、Interstage Application Server V9.0.1以降の"Interstage Application Server J2EEユーザーズガイド"を参照してください。
JNDIを使用してJMS Destinationオブジェクトをlookupして、メッセージを送信します。
java:comp/env/[deployment descriptorの<resource-ref>に指定したコネクションファクトリ名]
java:comp/env/[deployment descriptorの<message-destination-ref-name>に指定したDestination名]
package sample;
import javax.jms.*;
import javax.naming.*;
public class TopicClient {
public static void main(String[] args) {
try {
InitialContext initialContext = new InitialContext();
ConnectionFactory connectionFactory = (ConnectionFactory)
initialContext.lookup("java:comp/env/jms/ConnectionFactory");
Destination destination = (Destination)
initialContext.lookup("java:comp/env/jms/Topic");
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(destination);
TextMessage Message = session.createTextMessage( );
Message.setText( "Message" );
messageProducer.send(Message);
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

J2EEアプリケーションクライアントからJNDIを使用する場合は、JNDIサービスプロバイダの環境設定をする必要があります。JNDIサービスプロバイダの環境設定については、Interstage Application Server V9.0.1以降の"Interstage Application Server J2EEユーザーズガイド"を参照してください。
目次
索引
![]()
|