Messengerプロジェクトは、Tomcat4.0といったサーブレットエンジンで動くJMSベースのコンテナである
Messageletエンジンを提供します。
Messageletエンジンは、
一定のJMS MessageListners・Message稼動型オブジェクト・サーブレット・JSPを使った様々な
やり方の中で、JMSメッセージを処理するシンプルなフレームワークをMessageletエンジンは提供します。
Messageletコンテナをデプロイするために、ウェブアプリケーションにManagerServletを加え、
様々なJMS connectionsを全て記述したXMLの設定ファイルを加え、
subscriptionsを全て記述したXMLの設定ファイルを加えます。
connections
・subscriptions
のXML設定ファイルの例です。
以下のセクションを、Messageletマネジャーサーブレットをデプロイするためのweb.xml設定ファイルに加える
必要があります。
 |
 |
 |
 |
<servlet>
<servlet-name>managerServlet</servlet-name>
<servlet-class>org.apache.commons.messagelet.ManagerServlet</servlet-class>
<init-param>
<param-name>connections</param-name>
<param-value>/WEB-INF/Messenger.xml</param-value>
</init-param>
<init-param>
<param-name>subscriptions</param-name>
<param-value>/WEB-INF/subscriptions.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
|
 |
 |
 |
 |
一旦、上記の事を行ってしまって、ウェブアプリケーションが開始すれば、
Messageletエンジンは、様々なJMS subscriptionsをsubscribeし、次に
JMSメッセージを様々なMessageListnerオブジェクトやサーブレットあるいはJSPページに
送ります。
リクエストに依存するJMSメッセージを処理するには様々な方法があります。
-
MessageListenerは、メッセージの標準的なJMSリスナーです。
-
A MessageDrivenObject is-a JMS MessageListener which has
extra servlet-based lifecycle methods just like a Servlet.
This allows
an MDO to know when its being initialised and when its being destroryed
and so do some resource management (such as creating or closing database
connections etc). Also on initialisation the MDO gets access to the
ServletContext so that it can read some initialization parameters from
the web application or perform web-app level logging and so on.
-
A MessengerMDO is-a MessageDrivenObject
but also provides a number of helper methods such as access to the Messenger to
which its listening, so that responses can be sent back to the originator of the message,
as well as access to the ServletContext and some logging helper methods.
-
A Servlet can be any GenericServlet or HttpServlet.
If the JMS message that is being dispatched is a TextMessage then the body of the message is
available via the ServletRequest.getReader() method, in the normal Servlet way.
Any output written to the ServletResponse.getWriter() will be converted into a TextMessage
and sent back to the originator.
All servlets and JSP pages have access to the originating JMS message and Messenger objects via
the "message" and "messenger" request attributes respectively.
-
A Messagelet
is a JMS specific Servlet, just like a HttpServlet is a HTTP specific Servlet. It
provides access to a Messagelet specific
MessageletRequest
and
MessageletResponse
to allow access to the JMS Message and the Messenger for sending replies.
-
A JSP page can be any piece of JSP, for example the standard JSP tag library can be used
to perform JavaScript, XPath, XSLT or SQL operations on the incoming message.
The request scope "message" and "messenger" attributes can be used to access the originating
JMS Message and Messenger objects.
MDO・サーブレット・Messageletのサンプルが、
こちらにあります。また、
JSPサンプルは
こちらにあります。