COMP 655: Distributed/Operating Systems - Winter 2015 2025-01-30 18:24:25 UTC | |||||||||||||||||||||||
| JMS
JMS (Java Message Service) is the Java EE technology for non-blocking, persistent communication. It supports both message queuing (via JMS Queues) and publish-subscribe (via JMS Topics).
JMS for DiNo We won't use all of JMS in DiNo, of course. Furthermore, we will use our subset of JMS in an unusual way. Normally, JMS connection factories and destinations are created with administrative tools and last a long time - days or weeks in test environments, months or years in production. Clients look them up with JNDI, and JNDI naming hides differences among the various JMS providers. In DiNo, by contrast, we will create JMS resources dynamically, in a GlassFish-specific way. This non-portability is undesirable, but given our time constraints, the simplification that results from cutting out administrative tools and JNDI indirection will be worth it.Creating connection factories We will create JMS connection factories and topics in a GlassFish-dependent way. Specifically, to create a connection factory that talks to the local JMS provider, do
To create a connection factory that talks to the JMS provider on a remote machine,
Non-portability across JMS providers is clear here; another provider cannot be expected to implement com.sun.messaging.ConnectionFactory. (of course, all providers will implement javax.jms.ConnectionFactory) com.sun.messaging.ConnectionFactory is probably not in the jars that make up the normal GlassFish runtime environment. When working with the sample source code now, and your DiNo implementation later, you will need to include glassfish/lib/install/applications/jmsra/imqjmsra.jar in your project's build path. You do NOT need to include it in WAR or JAR files you deploy to GlassFish, because it is already on the container's classpath. When using the code above to connect to a remote provider, host should be a string of the form hostname or hostname:port. If the port number is not provided, it defaults to GlassFish's default JMS port, which is 7676. Creating topics Given a connection factory cf and a destination name dn, you can create a topic like this
The non-portability is somewhat hidden here: the destination name dn must be a String that conforms to rules defined by GlassFish's JMS provider IMQ. Specifically, dn can contain letters, digits, and underscores. I'm not certain what other characters may be legal, but slash (/) is not. Such names may or may not work with a different JMS provider. A nice characteristic of IMQ is that you do NOT have to create the named destination with an administrative tool or JMX. It will create physical destinations as needed. Those destinations are officially temporary, but from what I've seen so far, their lifetimes will be plenty for our purposes. jms-sample.war contains a RESTful web service that supports experimenting with a subset of JMS. Unless I have overlooked something, that subset is what we will need for DiNo. The sample can be downloaded into a GlassFish autodeploy directory and used via the RESTful client. Here's what it can do.
NOTES
|