Thursday, August 24, 2006

How to create a Queue/Topic in JBoss?

Queues/Topics are known as administered objects and in jboss they can be deployed through ServiceDotXml files. Let’s name our file, myapp-destination-service.xml. The contents of the file should look like:

<?xml version="1.0" encoding="UTF-8"?>

<!--My queue, named: myAppQueue -->
<mbean code=""
<depends optional-attribute-name="DestinationManager"></depends>
<!-- My topic, named: myAppTopic -->
<mbean code=""
<depends optional-attribute-name="DestinationManager"></depends>


Place this file in your %JBOSS_HOME%/server/default/deploy directory and start the server.
(Note: If you are using the ‘all’ configuration or the ‘minimal’ configuration then you will have to place this file in the %JBOSS_HOME%/server/all/deploy or %JBOSS_HOME%/server/minimal/deploy directory, as appropriate).

The above queue/topic will be bound to the jndi name: queue/myAppQueue and topic/myAppTopic respectively.


1) The above file is meant for JBoss-3.2.3. Though there might be slight changes to later versions of JBoss, the basic configuration mechanism remains the same.

2) JBoss also comes with preconfigured queues/topics. These configurations can be found in the jbossmq-destinations-service.xml file which is present in %JBOSS_HOME%/server/default/deploy/jms directory


For JBoss AS 6.x see this FAQ for more details on how to configure JMS queue/topics


T.RamMohanReddy said...


Thanks for the information..............

Anonymous said...

A mode I discovered to make topic at runtime is contained in the following code:

MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).iterator().next();
ObjectName factoryTopic = new ObjectName("", "service", "DestinationManager");
String sTopic = "TopicName";
ObjectName o = new ObjectName("", "name", "Topic/"+sTopic);
server.invoke(factoryTopic,"createTopic",new Object[] { sTopic },new String[]{ "java.lang.String" } );

You MUST add Exception management and insert into a MBean java class.

Sanjeev said...

I am new to JBOSS and need some spoonfeednig on configuring queues and topics, but not we are using MQ, we are using EJBs for handling messages. So, I am wondering why you arereferring classes present in 'mq' packages?

Anonymous said...

How to register the listener to dynamically created queue?

vishal said...

thanks for the help worked for me...

Anonymous said...


Thanks for your Info....
I have some problem related this topic.
I m trying to create new Topic/Queue at run time in JMS.
Using your code as reference, but there is Exception like

Here is my code...

String sTopic = "navnathTopic";
String type = "Topic";
String createType = "createTopic";
String jbossPackage = "";
String service = "service";

MBeanServer server = (MBeanServer)
null).iterator().next(); factoryTopic = new, service,
type + "/"+ sTopic);

server.invoke(factoryTopic, createType, new Object[] { sTopic },
new String[] { "java.lang.String" });

Any suggestions..... where I m wrong

Anonymous said...


This is Navnath. I had try your code and it's working fine. Prob was used ObjectName which is not present. Now I can create queue at run time. Now the problem is to bind that queue with existing Listener.
Please suggest me how do I do?