6 Replies Latest reply on May 20, 2003 8:56 AM by Adrian Brock

    building reliable server/client - help needed

    delboypass Newbie

      CURRENT SCENARIO
      -----------------------------------
      I have a bean set-up on a remote machine.
      This bean is setup to lookup the JNDI tree on the remote machine. (Specifically to get hte queueconnectionfactory)
      What we are currently trying to do is to get the bean to save a generated message to the remote queue when the server is down.

      On the remote Bean on create we set up the variables for everything.
      See code below. What this enables is that the remote bean gets all the configuration on start up from the server. Then if the server goes down, it cant send a message anymore. Through this configuration, there should be the remote queue (Queue/testqueue) and the server queue (Queue/testqueue) and if the remote bean finds the server down writes the message to the remote local queue but if hte server is up the message is sent to the server queue waiting to be consumed.

      REAL QUESTION
      -------------------------
      What I need to be able to do is to be able to reconnect the remote bean back to the server when it recognises that the server is back up and also persist the message that it was unable to deliver to the server on its own local queue, Queue/testqueue. (How to recognise that the server is down or does the jms implementation do that for us and the reconnection??How to manage the two identical queues on each machine so that they only hold a message in one or the other queues)

      What is the best way to be able to do this as perhaps the way in which im trying to do it is not the best (IE setting up the bean oncreate).

      Any test code available would be most useful.


      // remote bean code//
      try {
      InitialContext ic = new InitialContext();
      q = (Queue)ic.lookup("queue/testQueue");

      Context c = (Context) ic.lookup("java:/comp/env");
      qcf = (QueueConnectionFactory)c.lookup( "QueFactory" );

      } catch (NamingException e) {}

      try {
      qc = qcf.createQueueConnection();
      } catch (JMSException e) {}

      try {
      qs = qc.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
      } catch (JMSException e) {}

      try {
      qsend = qs.createSender(q);
      } catch (JMSException e) {}
      }

      //sending a message
      public String sendMsg(String msg)
      {
      TextMessage ms = null;
      try {
      ms = qs.createTextMessage();
      DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
      Date timeStamp= new Date();
      ms.setText("MDB message from queueService: "+ msg+ "\n" + df.format(timeStamp));
      qsend.send(ms, DeliveryMode.PERSISTENT, 2, 1000000);
      } catch (JMSException e) {}

      return "Message sent";
      }

      //end of remote bean code//

        • 1. Re: building reliable server/client - help needed
          Adrian Brock Master

          You should install an ExceptionListener on the
          connection. From there you can try to recover
          or reconnect.

          Regards,
          Adrian

          • 2. Re: building reliable server/client - help needed
            paulgammon Newbie

            Thanks for the reply.

            I do get a number of exceptions thrown on startup.
            Below is a summary of exception thrown and the
            associated JBoss facility

            java.util.zip.ZipException: error in opening zip file
            -----------------------------------------------------
            org.jboss.resource.connectionmanager.RARDeployment
            org.jboss.mail.MailService
            org.jboss.tm.TransactionManagerService
            org.jboss.jbossweb
            org.jboss.jetty.JettyService

            java.lang.SecurityException: Invalid authentication attempt, principal=null
            ---------------------------------------------------------------------------
            org.jboss.mq.pm.jdbc2.PersistenceManager
            org.jboss.system.ServiceController

            javax.jms.InvalidDestinationException: This destination is not open!
            --------------------------------------------------------------------
            org.jboss.mq.server.jmx.Topic.testTopic
            org.jboss.mq.server.jmx.Topic.securedTopic
            org.jboss.mq.server.jmx.Topic.testDurableTopic
            org.jboss.mq.server.jmx.Queue.testQueue

            javax.management.InstanceNotFoundException: jboss.management.local:J2EEApplication=jms,J2EEServer=Local,j2eeType=ResourceAdapterModule,name=jms-ra.rar is not registered.
            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            org.jboss.management.j2ee.ResourceAdapterModule

            I have also tried my test application using 3.2.0.
            JNDIView seemed to work correctly and the connection
            factory was located. However, my test application
            failed with

            Exception in thread "main" javax.jms.JMSSecurityException: User: null is NOT authenticated

            This has all been tested on Sun and HP and is known
            to work.

            Do you know if there are issues with AIX ?

            Many thanks


            • 3. Re: building reliable server/client - help needed
              delboypass Newbie

              Adrian, Do you have any examples of this.

              If i have set up all the variables in the remote beans oncreate and the server machine goes down. When it is restarted does the remote beans variables still remain pointed to the correct values on the server or because the server has been restarted do all the variables now need to be changed??

              • 4. Re: building reliable server/client - help needed
                paulgammon Newbie

                Apologies. Posted this to the wrong thread.

                • 5. Re: building reliable server/client - help needed
                  delboypass Newbie

                  PROBLEM
                  ------------------
                  Messages sent when connection was down are undelivered when a connection is re-established

                  --------------------------------------------------------------

                  Adrian, Ive implemented the OnException method and put an exception listener on the connection.

                  The problem we are still facing is, if we send a message but the connection pointed to the downed server, the message is never delivered.

                  Does this mean that the message holds the varibale names for other elements such as reference to the old queue or anything like that.

                  Basically the code is the same as above except moved all the oncreate stuff into a method called connectRemoteQueue.
                  if we get a connection exception, we use this code.
                  So what basically happens is we then reset all the variables. This allows use to re-establish a connection with the server, but it is still unable to deliver the mesasages that were sent when the server was down.

                  Any thoughts of a solution??

                  //connection exceptioncode//
                  public void onException (JMSException e)
                  {
                  //Report the Error and take necessary Error handling measures
                  System.out.println();
                  System.out.println("Derrick - trying to catch connection exception");

                  System.out.println (e.toString());
                  connectRemoteQueue();
                  System.out.println("Retried to connect to remote queue");
                  }
                  //end of connection exception code//

                  JBOSS EXCEPTION
                  -------------------------------------------------------------------
                  15:31:03,811 INFO [STDOUT] org.jboss.mq.SpyJMSException: Connection Failed; - nested throwable: (java.io.IOException: ping timeout.)

                  ---------------------------------------------------------------------
                  What do I have to do ?

                  • 6. Re: building reliable server/client - help needed
                    Adrian Brock Master

                    Which variables?

                    If you mean entity bean fields these are
                    persisted to the database.

                    Others are just work in progress,
                    they won't survive a crash unless you
                    persist them somewhere.

                    Regards,
                    Adrian