listening to multiple queues in sun message queue

Posted on 2007-10-11
Last Modified: 2008-02-14

i am trying to work with sun message queue, i am using jdk1.6 and the

latest sun message queue.  everything works fine if i have a receiver

listen to one queue, until i try to listen to a different queue with

a different receiver.  then i get this:

Exception occurred: javax.jms.ResourceAllocationException: [C4073]: A

JMS destin
ation limit was reached.  Too many Subscribers/Receivers for Queue :

stination_Object user=guest, broker=localhost:7676(1027)

does this mean i have to get a paid version of the sun message queue

to be able to listen to two queues at the same time? i read somewhere

that there is a property you can set that will increase the number of

queues you are allowed to use, but am not sure exactly how.  

My code is as follows:

 * The SimpleQueueReceiver class consists only of a main method,
 * which fetches one or more messages from a queue using
 * synchronous message delivery.  Run this program in conjunction
 * with SimpleQueueSender.  Specify a queue name on the command
 * line when you run the program.
import javax.jms.*;
import javax.naming.*;
import java.util.Properties;

public class SimpleQueueReceiver {
      //Initial context factory
      public static final String CTX_FACT =

      //Provider URL
      public static final String PROV_URL = "file:C:\\temp1";
      //JNDI name for the queue connection factory
      public static final String QCF_NAME = "QCFactory";
      //JNDI name for the topic connection factory
      public static final String TCF_NAME = "TCFactory";
      //JNDI name for the queue
      public static final String QUEUE_NAME = "myQueue";
      //JNDI name for the topic      
      public static final String TOPIC_NAME = "myTopic";

     * Main method.
     * @param args     the queue used by the example
    public static void main(String[] args) {
        String                  queueName = null;
        Context                 jndiContext = null;
        QueueConnectionFactory  queueConnectionFactory = null;
        QueueConnection         queueConnection = null;
        QueueSession            queueSession = null;
        Queue                   queue = null;
            QueueConnection queueConnection1 = null;
            QueueSession queueSession1 = null;
            Queue queue1 = null;
        QueueReceiver           queueReceiver = null;
            QueueSender                        queueSender =

        TextMessage             message = null;
         * Read queue name from command line and display it.
        if (args.length != 1) {
            System.out.println("Usage: java " +
                "SimpleQueueReceiver <queue-name>");
        queueName = new String(args[0]);
        System.out.println("Queue name is " + queueName);
         * Create a JNDI API InitialContext object if none exists
         * yet.
            Properties prop = new Properties();
            //Add the initial context factory
            prop.put(Context.INITIAL_CONTEXT_FACTORY, CTX_FACT);
            //Add the provider URL
            prop.put(Context.PROVIDER_URL, PROV_URL);
            //Create the initial context
            //Context ctx = new InitialContext(prop);
        try {
            jndiContext = new InitialContext(prop);
        } catch (NamingException e) {
            System.out.println("Could not create JNDI API " +
                "context: " + e.toString());
         * Look up connection factory and queue.  If either does
         * not exist, exit.
        try {
            queueConnectionFactory = (QueueConnectionFactory)

            queue = (javax.jms.Queue) jndiContext.lookup(queueName);
                  queue1 =

        } catch (NamingException e) {
            System.out.println("JNDI API lookup failed: " +

         * Create connection.
         * Create session from connection; false means session is
         * not transacted.
         * Create receiver, then start message delivery.
         * Receive all text messages from queue until
         * a non-text message is received indicating end of
         * message stream.
         * Close connection.
        try {
            queueConnection =
            queueSession =
            queueReceiver = queueSession.createReceiver(queue);

                  /*queueConnection1 =

                  queueSession1 =

                  queueSender =

            while (true) {
                Message m = queueReceiver.receive(1);
                        if (m != null)
                              if (m instanceof TextMessage)
                                    message =


System.out.println("Reading message: " +



                              TextMessage message1 =

                              message1.setText("This is

message 1");


        } catch (JMSException e) {
            System.out.println("Exception occurred: " +
        } finally {
            if (queueConnection != null) {
                try {
                } catch (JMSException e) {}
                  if (queueConnection1 != null)
                        catch (JMSException e) { }

Question by:mmingfeilam
    LVL 92

    Expert Comment


    Author Comment

    i modified C:\Sun\MessageQueue\var\instances\imqbroker\props\ to this:


    and restarted everything, but didn't work.  is there any other way to set the properties?  

    also, i noticed there is another similar file C:\Sun\AppServer\domains\domain1\imq\instances\imqbroker\props\  this one came with the installation of j2ee.  it's pretty confusing to me why there are two of them.
    LVL 92

    Accepted Solution

    one for the server, the other for the queue

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Help refactoring a java code 8 43
    hasOne  challenge 59 62
    json format text only 4 44
    solarwind tftp server 2 16
    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    The viewer will learn how to implement Singleton Design Pattern in Java.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now