Over a million developers have joined DZone.

Quick Reference for Configuring JMS Resources on Application Servers

DZone 's Guide to

Quick Reference for Configuring JMS Resources on Application Servers

· Java Zone ·
Free Resource

I'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.

  1. Click "File", "New File..."
  2. 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.
  3. Under "Categories:", select "Glassfish"
  4. Under "File Types:" (yes, that really is odd), select "JMS Resource"
  5. Click "Next" to create a ConnectionFactory
  6. In "JNDI Name:", enter "jms/connectionFactory" (or, your choice, of course)
  7. Ensure the new item is enabled
  8. Under "Choose Resource Type:", select "javax.jms.ConnectionFactory"
  9. Click "Finish" (unless you want to configure properties on the ConnectionFactory, in which case click "Next")
  10. Starting back at Step #1, create a JMS queue, following the above steps but this time selecting a resource type of "javax.jms.Queue"
  11. 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.
  12. 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".
  13. Repeat Steps 10-12 and create a Topic, remembering to choose resource type "javax.jms.Topic"
  14. Under the "Projects" tab, right-click on your Java EE project and select "Deploy".
  15. 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.
Much More Flexibility -- WebLogic Server

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
  1. In the WebLogic web console, expand "Services", then select "Persistent Stores".
  2. Above the Persistent Stores table, click "New", then (for this example) select "Create FileStore".
  3. 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.
  4. Enter a directory, paying attention to the accompanying text (in other words, ensure this is a real directory).
  5. Click OK.
Set up a JMS Server
  1. Under "Services", expand the "Messaging" node, then select "JMS Servers".
  2. Click the "New" button above the JMS Servers table.
  3. Enter a Name.
  4. Choose a persistent store. Note that the WLS console allows you to create one now, if you haven't yet done so.
  5. Click "Next".
  6. Choose a target for the JMS Server. Again, in my case, I chose the admin server.
  7. Click "Finish".
Set up a JMS Module
  1. Under "Services", "Messaging", select "JMS Modules".
  2. Click the "New" button above the JMS Modules table.
  3. Enter a Name, then click "Next".
  4. Again, choose a target, then click "Next" again.
  5. We could start adding resources, but for now just click "Finish".
Create a JMS Module Subdeployment
  1. Under "Services", "Messaging", "JMS Modules", select your new JMS Module.
  2. Click the "Subdeployments" tab.
  3. Above the table, click the "New" button.
  4. Enter a name for the subdeployment, then click "Next".
  5. 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.
  6. Click "Finish".
When you view this new Subdeployment under the "Subdeployments" tab for your new JMS Module, you should see your JMS Server under the "Targets" column, but nothing under the "Resources" column.

Finally, create your JavaEE JMS resources
  1. Under "Services", "Messaging", "JMS Modules", select your new JMS Module.
  2. Under the "Configuration" tab, click the "New" button.
  3. Select "Connection Factory", then click "Next".
  4. Enter a Name or accept the auto-populated default.
  5. Enter a JNDI name for the ConnectionFactory.
  6. Click "Next".
  7. Click "Advanced Targeting".
  8. 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.
  9. Click "Finish". Note that all the property columns are populated for the new resource.
  10. In the JMS Module "Configuration" tab, click the "New" button again.
  11. Select "Queue", then click "Next".
  12. Enter a Name and a JNDI Name, then click "Next".
  13. Choose a Subdeployment, then click "Finish".
  14. In the JMS Module "Configuration" tab, click the "New" button again.
  15. Select "Topic", then click "Next".
  16. Enter a Name and a JNDI Name, then click "Next".
  17. Choose a Subdeployment, then click "Finish".
At this point, you'll see that the JMS Module "Configuration" table contains your three new resources, as well as their subdeployment and targets. If you click on the "Subdeployments" tab, you will see that your new Subdeployment lists the three resources in that view as well. You should now be able to do a JNDI lookup of the resources, of course.

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.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}