7 Replies Latest reply on Aug 7, 2005 11:20 AM by tomerbd2

    send message only if not alredy in jms

    tomerbd2 Newbie

      is there a possibility to send a message to jms only if the message does not exist already in it? something like to first query the jms and if message is not in there then to send it...

        • 1. Re: send message only if not alredy in jms
          Ulf Schroeter Novice

          DO NOT misuse JMS messaging for things it's not designed for ! The main purpose of JMS is fire-and-forget messaging.

          Rethink your general solution approach ! What you are describing is the following: select a dataobject based on some critieria, if the resultset is empty then insert a new dataobject .... sounds to me like a classical database use case.

          Regards
          Ulf

          • 2. Re: send message only if not alredy in jms
            tomerbd2 Newbie

            Hi

            I have users, im polling their emails accounts

            Here is the scenario:

            1. For each user that its polling time reached send a jms message.
            2. Many workers are listening to the jms message in queue one of them receives the jms messages and syhcornizes that user's email account.

            Now lets say polling time is every 1 hour, lets say user 'tomer' already has a message in queue waiting to be taken out in order to synchronize his account and another polling cycle has arrived i do not want to insert another message into the queue.

            What do you say?

            • 3. Re: send message only if not alredy in jms
              Ulf Schroeter Novice

              >What do you say ?

              Use scheduler service

              • 4. Re: send message only if not alredy in jms
                tomerbd2 Newbie

                > Use scheduler service

                It wont be as good as a jms solution.

                • 5. Re: send message only if not alredy in jms
                  Ulf Schroeter Novice

                  >It wont be as good as a jms solution.

                  such a good jms solution that you ask for help on your problems... :-)

                  Ok, different approach. I guess (as you talk about 'user that its polling time is reached' ) that you have some kind of persistent user record with attributes like email address, polling time, ....

                  Add a state flag like 'SynchronizationScheduled', check/set this flag before sending a message and schedule message only if it's not already set. Reset flag fom within the mdb after synchronization.

                  Don't try to misuse a JMS message as state information "synchronization already on its way" as it will fail by design ! As soon as an mdb has picked the triggering message from the queue for a longer running synchronization (I guess that's why you want to use mdb's) there is no more indication to your jms sender that a synchronization is already currently running. Sounds like the old problem...

                  • 6. Re: send message only if not alredy in jms
                    tomerbd2 Newbie

                    Thanks, well sounds like a good solution (i thought about it as well ;) however i would like to investigate some more options comming to this investigation i noticed that in the jmx-console there is this :

                    java.util.List listMessages()

                    MBean Operation.


                    for the specific queue in the URL like:
                    http://localhost:8080/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.mq.destination%3Aservice%3DQueue%2Cname%3Dyour_queue_name


                    Now i invoked the listMessages() operation and i saw no messages on screen its empty [] , i know i have messages in the queue, i can even see them in the database that holds the messages... is this a bug?


                    Moreover i wrote some code that browses all messages in queue and it returns nothing, as if it thinks there are no messages in queue... i think its related to the fact that the jmx listMessages() returned an empty list (perhaps the same bug)

                    here is my code:

                     public Enumeration listMessages() {
                     // http://wiki.jboss.org/wiki/Wiki.jsp?page=JmsBrowserBean
                     QueueSession session = null;
                     QueueBrowser browser = null;
                     Enumeration queueContents = null;
                     String messageSelector = null; // http://infocenter.sybase.com/help/topic/com.sybase.help.easerver_5.2/html/easpg/easpgp538.htm#BABCGIJE
                     // http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/Message.html
                    
                     try {
                     session = _queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
                     if (messageSelector != null) {
                     browser = session.createBrowser(_queue, messageSelector);
                     } else {
                     browser = session.createBrowser(_queue);
                     }
                     queueContents = browser.getEnumeration();
                     while (queueContents.hasMoreElements())
                     _log.debug(queueContents.nextElement()); // nothing :( although i have messages... nothing in this enumeration... :( why???
                     } catch (JMSException e) {
                     throw new InternalException(e);
                     } finally {
                     closeQueueBrowser(browser);
                     closeSession(session);
                     }
                     return queueContents;
                     }
                    


                    • 7. Re: send message only if not alredy in jms
                      tomerbd2 Newbie

                      Hi

                      So... anyway can tell me regarding my previous message is the jmx console java.util.List listMessages() (and the implementation that i used) is working or not?