2 Replies Latest reply: Nov 22, 2011 8:49 AM by 899681 RSS

    Exception for simultaneous Topic Session


      I have a Multi Consumer enabled queue with a single subscriber defined. I wrote a simple Java client to connect to the queue and dequeue messages. I was surprised to see that I can run two instances of my client simultaneously without receiving an error message. What's even more worrying is the second client to connect just sits there while the original client dequeues the messages. Is there a way to code the Java client so it will fail to connect if another client is already connected to the queue using the same username?


        • 1. Re: Exception for simultaneous Topic Session

          I am possibly missing something but I am not sure why you are surprised by this behaviour. If I connect to the database as a user which has privileges to select from a table my expectation would be that multiple sessions would be able to select from the same table. Fundamentally a dequeue is not any different. Multiple sessions can consume messages for a particular subscriber. There is no way to prevent this that I am aware of. Why do your require this?

          I am surprised that the second session is not able to consume any messages but it may depend on how it has been coded.

          Can you post your dequeue code and confirm the version of database and the jar files you are using?

          • 2. Re: Exception for simultaneous Topic Session
            Hi Peter.

            I guess I'm surprised by the behaviour mainly because of the fact I'm only seeing the messages in one of the clients. So, it seems like you could have a situation where someone is connected to the queue as a particular user by mistake, and they are dequeuing messages, meanwhile the app you intend to dequeue the messages is sitting their oblivious (not receiving notification of new messages).

            We're using 11.2g, and the jars are from the 11.2 distribution. The java code in question is basically a sample I downloaded from the internet. The real clients of the queue will be written in C++ later. I just observed this behaviour and found it strange. Anyway, here is the code (with some needless details removed):

            public class UpdateListener implements MessageListener
                 private TopicConnection connection;
                 private TopicSession subSession;
                 * Constructor
                 public UpdateListener(String host, String database, String queueName, String username, String password) throws Exception {
                      TopicConnectionFactory connectionFactory = AQjmsFactory.getTopicConnectionFactory(host, database, 1521, "thin");
                      TopicConnection connection = connectionFactory.createTopicConnection( username,password);

                      TopicSession subSession = connection.createTopicSession(true, Session.CLIENT_ACKNOWLEDGE);
                      Topic topic = ((AQjmsSession)subSession).getTopic("xxxxx", queueName);          
                      ORADataFactory orad = MessageType.getORADataFactory();
                      TopicReceiver receiver = ((AQjmsSession)subSession).createTopicReceiver(topic, username, null,orad);
                      set(connection, subSession);
                      connection.start() ;
                 public static void main(String[] args) {
            if (args.length!=5)
            System.out.println("<Host> <DB Name> <Queue Name> <Username> <Password>");

            UpdateListener ul = new UpdateListener(args[0],args[1],args[2],args[3],args[4]);

            // Read from command line
            BufferedReader commandLine = new
            java.io.BufferedReader(new InputStreamReader(System.in));

            // Loop until the word "exit" is typed
            String s = commandLine.readLine( );
            if (s.equalsIgnoreCase("exit")){
                 ul.close( ); // close down connection
            System.exit(0);// exit program
            } catch (Exception e){ e.printStackTrace( ); }

                 /* (non-Javadoc)
                 * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
                 public void onMessage(Message arg0) {
                      try {
                           if (arg0 instanceof AdtMessage) {
                                AdtMessage adtMsg = (AdtMessage) arg0;
                                if (adtMsg.getAdtPayload() instanceof MessageType) {
                                     MessageType message = (MessageType) adtMsg
                                     System.out.println("Dequeued message. id: "
                                               + message.getId());
                      } catch (JMSException jmse) {
                      } catch (SQLException e) {

            Thanks for replying.