¸Þ½ÅÀú ÇÁ·ÎÁ§Æ®´Â Tomcat4.0 µîµîÀÇ ¾î´À ¼ºí¸´¿£Áø¿¡¼µµ ´Þ¸®´Â JMS±â¹Ý ÄÁÅ×À̳ÊÀÎ Messagelet¿£ÁøÀ» Á¦°øÇÑ´Ù. Messagelet
¿£ÁøÀº JMS ¸Þ¼¼Áö¸®½º³Êµé, ¼ºí¸´µé ¶Ç´Â ½ÉÁö¾î JSP±îÁöµµ »ç¿ëÇÏ´Â ¹æ´ëÇÑ ¹æ¹ýÀ¸·Î JMS ¸Þ¼¼ÁöµéÀ» ó¸®Çϱâ À§ÇÑ °£´ÜÇÑ ÇÁ·¹ÀÓ¿öÅ©¸¦
Á¦°øÇÑ´Ù.
Messagelet ÄÁÅ×À̳ʸ¦ ¼³Ä¡Çϱâ À§ÇÏ¿©you need to add the ManagerServlet in a web application
giving it an XML configuration file describing all the various JMS connections
and an XML configuration file describing all the subscriptions.
Here are example
connections
and
subscriptions
XML configuration files.
There now follows the section you need to add to your web.xml configuration file to deploy the
Messagelet Manager Servlet.
|
|
|
|
<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>
|
|
|
|
|
Once you've done the above and the web application is started the Messagelet engine will
subscribe to the various JMS subscriptions and then dispatch JMS messages to the various
MessageListener objects, Servlets or JSP pages.
There are a variety of ways in which you can process JMS messages depending on your requirements.
-
A MessageListener is a standard JMS listener of messages.
-
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.
There are some examples of an MDO, Servlet and Messagelet
here or
you can see example JSP
here