|
 |
|
Depends: |
log |
Related: |
n/a |
|
|
|
Description
'jms' implements many well-known and often practiced JMS usage patterns. Note that the goal of this
service is not to replace JMS API but to provide a complementary implementation for some frequently used JMS
design patterns. Main features of the 'jms' service include but not limited to:
-
Smart connections - provides support for self-recoverable JMS connections.
-
Message to object conversion - automatic conversion between user objects and JMS messages.
-
Object senders and receivers - add support for user object sending and receiving as well
as waiting for and sending replies in thread-safe manner.
-
Thread safety - all classes provided by xTier jms service are safe to be used
by multiple threads.
Top
Configuration
'jms' service is configured via pre-defined xtier_jms.xml configuration file. This file
follows standard xTier service configuration pattern that can be demonstrated by the following complete example
of jms configuration:
| 1 |  | <region name="examples"> |
| 2 |  | <!-- |
| 3 |  | |
| 4 |  | |
| 5 |  | |
| 6 |  | |
| 7 |  | |
| 8 |  | |
| 9 |  | |
| 10 |  | --> |
| 11 |  | <msg-defaults priority="4" ttl="0" |
| 12 |  | delivery-mode="non-persistent" |
| 13 |  | disable-msg-id="true" |
| 14 |  | disable-msg-timestamp="false"> |
| 15 |  | <!-- |
| 16 |  | |
| 17 |  | |
| 18 |  | |
| 19 |  | --> |
| 20 |  | <obj-converter> |
| 21 |  | <ioc policy="singleton"> |
| 22 |  | <java class="com.fitechlabs.xtier.services. |
| 23 |  | jms.converters.JmsDefaultConverter"/> |
| 24 |  | </ioc> |
| 25 |  | </obj-converter> |
| 26 |  | </msg-defaults> |
| 27 |  | |
| 28 |  | <!-- |
| 29 |  | |
| 30 |  | --> |
| 31 |  | <conn-factory name="conn-factory"> |
| 32 |  | <ioc-factory> |
| 33 |  | <ioc policy="singleton"> |
| 34 |  | <!-- |
| 35 |  | |
| 36 |  | |
| 37 |  | --> |
| 38 |  | <java class="QueueConnectionFactory"/> |
| 39 |  | </ioc> |
| 40 |  | </ioc-factory> |
| 41 |  | |
| 42 |  | <!-- |
| 43 |  | |
| 44 |  | --> |
| 45 |  | </conn-factory> |
| 46 |  | |
| 47 |  | <!-- |
| 48 |  | |
| 49 |  | --> |
| 50 |  | <xa-conn-factory name="xa-conn-factory"> |
| 51 |  | <ioc-factory> |
| 52 |  | <ioc policy="singleton"> |
| 53 |  | <!-- |
| 54 |  | |
| 55 |  | |
| 56 |  | --> |
| 57 |  | <java class="XAQueueConnectionFactory"/> |
| 58 |  | </ioc> |
| 59 |  | </ioc-factory> |
| 60 |  | |
| 61 |  | <!-- |
| 62 |  | |
| 63 |  | --> |
| 64 |  | <smart-conn retries="3" retry-timeout="4000"/> |
| 65 |  | </xa-conn-factory> |
| 66 |  | |
| 67 |  | <!-- |
| 68 |  | |
| 69 |  | --> |
| 70 |  | <conn-factory name="jndi-factory"> |
| 71 |  | <jndi-factory name="jndi-conn-factory-name"/> |
| 72 |  | </conn-factory> |
| 73 |  | </region> |
Formal sepcification for this service configuration can be found in xtier_jms.dtd file in
${XTIER_ROOT}/config/dtd folder. Following is detailed description of jms configuration
parameters.
| msg-defaults |
This element specified default parameters for object sending and receiving via
JmsObjectSender and JmsObjectReceiver. Following are default values
if user omits to specify them explicitely in XML:
- delivery-mode - DEFAULT_DELIVERY_MODE
- priority - Message#DEFAULT_PRIORITY
- ttl - Message#DEFAULT_TIME_TO_LIVE
- is-disable-msg-id - false
- is-disable-msg-timestamp - false
|
| conn-factory |
This element specifies JMS connection factory. There are 2 ways to specify JMS connection
factory: as IoC object or through JNDI lookup. Following are explanations of IoC and JNDI
definitions.
-
ioc-factory - contains IoC definition. For information how to use IoC refer
to IocService documentation.
-
jndi-factory - Instance of connection factory will be looked up from JNDI
tree using 'name' attribute as a name.
|
| xa-conn-factory |
This element specifies JMS XA connection factory. XA connection factory configuration
is identical to regular connection factory configuration.
|
Top
Examples
Usage of 'jms' service follows the standard pattern of using xTier service: you need to obtain
an instance of xTier kernel that serves as a service registry. Once you have xTier kernel you can get
an instance of any service, in our case the 'jms' service. Once the service instance is obtained
the service API can be used.
Following code snippet is taken out from jms service example:
| 1 |  | |
| 2 |  | |
| 3 |  | |
| 4 |  | assert jms.getConnFactory("conn-factory") != null; |
| 5 |  | |
| 6 |  | |
| 7 |  | |
| 8 |  | XAConnection xaConn = jms.getXaConn("xa-conn-factory"); |
| 9 |  | |
| 10 |  | |
| 11 |  | jms.close(xaConn); |
| 12 |  | |
| 13 |  | |
| 14 |  | |
| 15 |  | |
| 16 |  | JmsSmartConnection smartConn = |
| 17 |  | jms.getSmartConn("conn-factory"); |
| 18 |  | |
| 19 |  | |
| 20 |  | assert smartConn.isOnline() == true; |
| 21 |  | |
| 22 |  | |
| 23 |  | smartConn.addExceptionListener(new ExceptionListener() { |
| 24 |  | public void onException(JMSException error) { |
| 25 |  | System.out.println("Error in smart connection."); |
| 26 |  | |
| 27 |  | error.printStackTrace(); |
| 28 |  | } |
| 29 |  | }); |
| 30 |  | |
| 31 |  | |
| 32 |  | |
| 33 |  | |
| 34 |  | |
| 35 |  | assert smartConn.getConn() != null; |
| 36 |  | |
| 37 |  | |
| 38 |  | |
| 39 |  | |
| 40 |  | smartConn.reset(); |
| 41 |  | |
| 42 |  | |
| 43 |  | smartConn.close(); |
Download xTier for full examples and documentation.
Top
|