• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

duplicate messages JMS

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I had a doubt. Is it possible that due to any circumstance, can a queue send multiple messages to the listener.
Or that by any chance, a duplicate message is posted to the queue and the same message is processed twice?
On a broader outlook, my question is that can there be a scenario due to which there can be duplication of a message in JMS(due to queue being hung or any other reason)?

 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Preet,

Yes it's possible. JMS providers have a retry concept. If registered subscribers are not reachable, then message sending is retried a number of times with delays inbetween them. Retry also occurs if the session specifies CLIENT_ACKNOWLEDGE but the subscriber fails to acknowledge a message.

Cheers
Karthik
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read: KeepItDown

I have removed the all uppercase subject for you.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A duplicate message is not a retry message. There is a subtle and important difference.

As has been correctly pointed out, retry means that the message processor (A Listener or an MDB) did not either receive the message or did receive the message but failed to process it (due to some reason). In this case, the processor did not wilfully acknowledge the message forcing the container to redeliver it. This is part of the 'guaranteed messaging' principle offered by jms.

Duplicate messages on the other hand is an erroneous situation that needs to be guarded against in the message processor logic. With duplicate messages, the same message is delivered multiple times . This may happen due to a communication break down after processing but just before acknowledgement.

ram.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar problem,

In our application we have an API which goes asynchronous after some point of time. Once it becomes asynchronous it goes to queue as a JMS message.

Now what has happened recently in our production environment is, the API got executed on 31st March and it has put a message to the queue, now that message for some reason didn't got executed. After 2 days the server got restarted and the message got executed twice.

So my question is,

Why the message didn't got executed? and for what reason it got executed after restart? and why twice?

Your inputs on this will be of great help in analyzing this issue.

Regards,
Kapil
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please read Use One Thread Per Question

You have to provide some more information. How do you know the message was not delivered? It's more probable that it got delivered and was not acknowledged or else the acknowledgement failed. What kind of acknowledgement do you use? What is the Message Listener? An MDB?

ram.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually  we are using tibco queue and MessageListener  to listen the message from Queue but same message processed multiple times below is my logic.

if (jndiProviderUrl.indexOf("ssl://") >= 0) {
                         
                   env.put(Context.SECURITY_PRINCIPAL, jndiSecurityPrincipal);

                   if (queueConnectionFactorynamePassword != null)
                          env.put(TibjmsContext.SSL_TRUSTED_CERTIFICATES, sslTrustedStore);
             
                   if (tmpdir != null) {
                       if (sslPassword == null) {
                           System.err.println("Error: SSL Password Error");
                           System.exit(-1);
                       }
                       env.put(TibjmsContext.SSL_IDENTITY, tmpdir);
                       env.put(TibjmsContext.SSL_PASSWORD, sslPassword);
                       env.put("com.tibco.tibjms.ssl.password", sslPassword);
                       
                   }

               
                   env.put(TibjmsContext.SSL_ENABLE_VERIFY_HOST, new Boolean(false));

                   env.put(TibjmsContext.SECURITY_PROTOCOL, "ssl");
                   env.put(TibjmsContext.SSL_CIPHER_SUITES, "DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA");

                   
                   com.tibco.tibjms.TibjmsSSL.setSecureRandom(createUnsecureRandom());
                   
                   env.put(Context.INITIAL_CONTEXT_FACTORY, "com.tibco.tibjms.naming.TibjmsInitialContextFactory");
                      env.put(Context.PROVIDER_URL, jndiProviderUrl);

env.put(Context.PROVIDER_URL, jndiProviderUrl);

                    InitialContext jndiContext = new InitialContext(env);
                   

                    /*
                    * Lookup queue connection factory which must exist in the factories
                    * configuration file.
                    */
                    QueueConnectionFactory queueFactory = (QueueConnectionFactory) jndiContext.lookup(queueConnectionFactoryName);
                    System.err.println("OK - successfully did lookup of " + queueConnectionFactoryName + ", " + queueFactory);
                   
                   

                    /*
                    * Lookup queue, which must exist in the queues configuration file of JNDI and
                    * broker, if not successful then it is most likely that such queue does not
                    * exist in the configuration files
                    */

                    javax.jms.Queue sampleQueue = null;

                    try {
                          sampleQueue = (javax.jms.Queue) jndiContext.lookup(jndiQueueName);
                          System.err.println("OK - successfully did lookup queue '" + jndiQueueName + "'");
                    } catch (NamingException ne) {
                          System.err.println("**NamingException occurred while lookup the queue" + jndiQueueName);
                          System.err.println("  Most likely such queue does not exist in your configuration.");
                          System.err.println("  Exception message follows:");
                          System.err.println(ne.getMessage());
                          System.exit(0);
                    }

                    /*
                    * Let's create a queue connection to the server and a session to verify the
                    * server is running so we can continue with our lookup operations.
                    */
                    QueueConnection queueConnection = null;
                    QueueSession queueSession = null;
                    MessageConsumer msgConsumer = null;

                    try {
                          if (jndiProviderUrl.indexOf("ssl://") >= 0) {

                                 /*
                                 * Set the password key for the keystore returned by the JNDI
                                 */
                                 char[] sslpassword = ssl_keypass.toCharArray();
                                 com.tibco.tibjms.TibjmsSSL.setPassword(sslpassword);

                                 queueConnection = queueFactory.createQueueConnection();
                          }
                         
                          queueSession = queueConnection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
                          /*
                          * Starting an asynchronous queue subscriber
                          */
                          System.err.println("Subscribing to Queue: " + jndiQueueName + "'\n");
                          msgNumber = 0;
                           
 

                          catejmsjndiQueueListenerClient.Subscriber(queueConnection, queueSession, sampleQueue, msgConsumer);

public void Subscriber(Connection subsConnection, Session subsSession, Destination destination, MessageConsumer msgConsumer)
{
    try {
        /*
         * Creates the consumer
         */

        msgConsumer = subsSession.createConsumer(destination);

        /*
         * Set the message listener
         */
        msgConsumer.setMessageListener(this);

        /*
         *  Start the connection
         */
        subsConnection.start();
       
     
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}


Listener code :

MessageListener:
public void onMessage(Message msg)
   {
       
       try
       {
           
    if (msg instanceof TextMessage) {
   
   
    String orderResponse = ((TextMessage) msg).getText();
   
    storeOrderService.convertXmlintoObject(orderResponse);
   
    msg.acknowledge();
    }
       }
       catch(Exception e)
       {
           System.err.println("Unexpected exception in the message callback!");
           e.printStackTrace();
           System.exit(-1);
       }
   
       }

 
Please provide any thing wrong i did?


 
Honk if you love justice! And honk twice for tiny ads!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic