Quick Reference for Configuring JMS Resources on Application Servers
Join the DZone community and get the full member experience.
Join For FreeI've recently been writing JMS clients for an application I'm building
and keep finding myself having to re-learn some basic configuration.
While some standalone JMS servers are still quite simple to configure,
the JMS resources of some application servers have become somewhat
complex to configure over the years. I'm quite sure I remember, in an
earlier version of WebLogic Server, going to a JMS page and configuring a
topic or queue on-the-spot. Those days are gone. Below are notes
which, if nothing else, will help me if I forget. It's not an
exhaustive list, of course; just the products I happen to be working
with now.
The Simple Cases
These are Apache's ActiveMQ and Allure Technology's JetStreamQ.
There's not much to say here; once you get the server running (which
itself is a very simple step), you create JMS resources in your Java
code and they're, well, just there for you to use. What a concept!
A Little More Complexity: Glassfish
For Glassfish,
you need to set up your JMS connection factories, queues, topics, etc.
in the application server. I use NetBeans (v 7.1) to manage the server.
This procedure is still fairly simple, although the concept of
referring to JMS resources as File resources seems a little odd to me.
The following steps assume you have started Glassfish and that you have
at least one application deployed to Glassfish.
- Click "File", "New File..."
- In the "New File" dialog, ensure that your application is selected in the "Project" combo. One thing I've noticed here is that you need to pop the combo and select an actual JavaEE component. If you add the JMS resource to the overall NetBeans project, it appears to go to /dev/null. You'll notice this later when you can't find your resource.
- Under "Categories:", select "Glassfish"
- Under "File Types:" (yes, that really is odd), select "JMS Resource"
- Click "Next" to create a ConnectionFactory
- In "JNDI Name:", enter "jms/connectionFactory" (or, your choice, of course)
- Ensure the new item is enabled
- Under "Choose Resource Type:", select "javax.jms.ConnectionFactory"
- Click "Finish" (unless you want to configure properties on the ConnectionFactory, in which case click "Next")
- Starting back at Step #1, create a JMS queue, following the above steps but this time selecting a resource type of "javax.jms.Queue"
- Note that a Queue (or Topic) requires at least one property, which is its name, which is the reason you can't just click "Finish". Go to the properties screen and supply a name.
- If you're using NetBeans 7.1, you'll notice this still isn't enough to complete the task, because of a bug in the dialog(missing document listener). After entering a value for the name, click in the "Name" field and the "Finish" button should be enabled. Click "Finish".
- Repeat Steps 10-12 and create a Topic, remembering to choose resource type "javax.jms.Topic"
- Under the "Projects" tab, right-click on your Java EE project and select "Deploy".
- Under the "Services" tab, expand your running Glassfish server instance, right-click on "Resources" and choose "Refresh". You should see your new ConnectionFactory, Queue and Topic in their respective folders, and you should now be able to look them up by their JNDI names.
In WebLogic, before you create JMS resources, you have to decide how you want messages to be persisted, among other things. There's a fair amount of setup, and it makes sense to just back up all the way to the beginning, rather than try to figure out why your new resource is useless. I'm using WebLogic 12c in this example.
Set up a persistent JMS store
- In the WebLogic web console, expand "Services", then select "Persistent Stores".
- Above the Persistent Stores table, click "New", then (for this example) select "Create FileStore".
- Choose a target server; in my case I have an admin server and two managed nodes, and I chose the admin server as the target.
- Enter a directory, paying attention to the accompanying text (in other words, ensure this is a real directory).
- Click OK.
- Under "Services", expand the "Messaging" node, then select "JMS Servers".
- Click the "New" button above the JMS Servers table.
- Enter a Name.
- Choose a persistent store. Note that the WLS console allows you to create one now, if you haven't yet done so.
- Click "Next".
- Choose a target for the JMS Server. Again, in my case, I chose the admin server.
- Click "Finish".
- Under "Services", "Messaging", select "JMS Modules".
- Click the "New" button above the JMS Modules table.
- Enter a Name, then click "Next".
- Again, choose a target, then click "Next" again.
- We could start adding resources, but for now just click "Finish".
- Under "Services", "Messaging", "JMS Modules", select your new JMS Module.
- Click the "Subdeployments" tab.
- Above the table, click the "New" button.
- Enter a name for the subdeployment, then click "Next".
- Select a target. This time, instead of targeting to the admin server or managed nodes, target the subdeployment to the JMS Server you created earlier.
- Click "Finish".
Finally, create your JavaEE JMS resources
- Under "Services", "Messaging", "JMS Modules", select your new JMS Module.
- Under the "Configuration" tab, click the "New" button.
- Select "Connection Factory", then click "Next".
- Enter a Name or accept the auto-populated default.
- Enter a JNDI name for the ConnectionFactory.
- Click "Next".
- Click "Advanced Targeting".
- Choose the Subdeployment you created above. Note that the form now populates with possible targets, but also note that the Subdeployment is already shown to be targeted, as you configured this property earlier.
- Click "Finish". Note that all the property columns are populated for the new resource.
- In the JMS Module "Configuration" tab, click the "New" button again.
- Select "Queue", then click "Next".
- Enter a Name and a JNDI Name, then click "Next".
- Choose a Subdeployment, then click "Finish".
- In the JMS Module "Configuration" tab, click the "New" button again.
- Select "Topic", then click "Next".
- Enter a Name and a JNDI Name, then click "Next".
- Choose a Subdeployment, then click "Finish".
I hope the above information is helpful. I think the Glassfish documentation is quite simple and to-the-point, as well as easy to find from the NetBeans help menu. The WebLogic documentation is a lot more spread out and it took me quite a while to figure everything out, which involved a lot of strange deployment error messages along the way. Please let me know if you find any mistakes. Good luck!
From http://wayne-adams.blogspot.com/2012/02/jms-resource-configuration-notes.html
Opinions expressed by DZone contributors are their own.
Comments