• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 910
  • Last Modified:

listening to multiple queues in sun message queue

hi,

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 :

Untitled_De
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 =

"com.sun.jndi.fscontext.RefFSContextFactory";
      //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 =

null;
        TextMessage             message = null;
               
        /*
         * Read queue name from command line and display it.
         */
        if (args.length != 1) {
            System.out.println("Usage: java " +
                "SimpleQueueReceiver <queue-name>");
            System.exit(1);
        }
        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());
            System.exit(1);
        }
       
        /*
         * Look up connection factory and queue.  If either does
         * not exist, exit.
         */
        try {
            queueConnectionFactory = (QueueConnectionFactory)
                        

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

(javax.jms.Queue)jndiContext.lookup("MyQueue1");
        } catch (NamingException e) {
            System.out.println("JNDI API lookup failed: " +
                e.toString());
            System.exit(1);
        }

        /*
         * 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 =
                queueConnectionFactory.createQueueConnection();
            queueSession =
                queueConnection.createQueueSession(false,
                    Session.AUTO_ACKNOWLEDGE);
            queueReceiver = queueSession.createReceiver(queue);

                  /*queueConnection1 =
                        

queueConnectionFactory.createQueueConnection();
                  queueSession1 =
                        

queueConnection1.createQueueSession(false,
                              Session.AUTO_ACKNOWLEDGE);
                  queueSender =

queueSession1.createSender(queue1);*/
                  
            queueConnection.start();
                  //queueConnection1.start();
            while (true) {
                Message m = queueReceiver.receive(1);
                        if (m != null)
                        {
                              if (m instanceof TextMessage)
                              {
                                    message =

(TextMessage)m;
                                    

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

message.getText());

                                    

//queueSender.send(message);
                              }
                        }
                        /*else
                        {
                              TextMessage message1 =

queueSession1.createTextMessage();
                              message1.setText("This is

message 1");
                              queueSender.send(message1);
                        }*/

            }

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

thanks
0
mmingfeilam
Asked:
mmingfeilam
  • 2
1 Solution
 
objectsCommented:
0
 
mmingfeilamAuthor Commented:
i modified C:\Sun\MessageQueue\var\instances\imqbroker\props\config.properties to this:

imq.adminkey=22357377211093205602936629876
imq.instanceconfig.version=300
imq.autocreate.queue.maxNumActiveConsumers=10

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\config.properties.  this one came with the installation of j2ee.  it's pretty confusing to me why there are two of them.
0
 
objectsCommented:
one for the server, the other for the queue
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now