3 Replies Latest reply on Jul 18, 2006 4:58 AM by timfox

    Reuse of sent ObjectMessages

    rtm333

      Hi,

      We are using JBoss Messaging 1.0.1 CR3 with JBoss 4.0.4 GA.

      Our publisher reuses ObjectMessage objects after they have been sent to a Topic. In my opinion, this is according to section 3.9 of the JMS 1.1 spec. It works with the WLS and MQ implementations.

      With Messaging it seems that the consumers are always receiving the same (the first?) payload over and over again with each message. As a workaround, calling clearBody() before setObject() seems to fix the problem.

        • 1. Re: Reuse of sent ObjectMessages
          timfox

          Can you explain in some more detail what you're seeing?

          So example code would be good.

          Thanks.

          • 2. Re: Reuse of sent ObjectMessages
            rtm333

            I've tried to extract the relevant code snippets from our application.

            If the method sendPriceMessage() is called repeatedly with differing arguments, say

            sendPriceMessage(priceA);
            sendPriceMessage(priceB);
            sendPriceMessage(priceC);

            the consumer receives priceA three times.

            Hope this clarifies the issue.

            Thanks.

            package notification;
            
            import javax.jms.*;
            import javax.naming.*;
            
            public class PriceChangePublisher {
            
             private TopicConnection topicConnection;
             private TopicSession topicSession;
             private TopicPublisher topicSender;
             private ObjectMessage priceMsg = null;
            
             public PriceChangePublisher() {
             try {
             InitialContext ic = ServerConnectionHelper.getInitialContext();
             Topic topic = ServerConnectionHelper.getPriceNotificationTopic(ic);
             TopicConnectionFactory factory = ServerConnectionHelper.getTopicConnectionFactory(ic);
             topicConnection = factory.createTopicConnection();
             topicConnection.setClientID("PricePublisher");
             topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
             topicSender = topicSession.createPublisher(topic);
             topicConnection.start();
             topicSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
             topicSender.setTimeToLive(300000);
             } catch (Exception e) {
             e.printStackTrace();
             }
             }
            
             public void sendPriceMessage(PriceModel price) {
             long timestamp = price.getTimeStamp().getTime();
             try {
             if (priceMsg == null) {
             priceMsg = topicSession.createObjectMessage();
             }
             synchronized (priceMsg) {
             // priceMsg.clearBody();
             priceMsg.setObject(price);
             priceMsg.setLongProperty("TIMESTAMP", timestamp);
             topicSender.publish(priceMsg);
             }
             } catch (Exception e) {
             e.printStackTrace();
             }
             }
            
            }
            


            • 3. Re: Reuse of sent ObjectMessages
              timfox

              I have seen something similar which is now fixed in CVS
              http://jira.jboss.com/jira/browse/JBMESSAGING-436