Forums Register Login

duplicate messages JMS

+Pie Number of slices to send: Send
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)?

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Please read: KeepItDown

I have removed the all uppercase subject for you.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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?


He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6470 times.
Similar Threads
how to poll a jms queue or topic for message using asynchronous communication
JMS - MDB
Handling poision messages in error queue
MQSeries and GlassFish JMS
Specifying JMS Queue size in OAS
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:10:29.