Announcement Announcement Module
Collapse
No announcement yet.
Class Members not getting set in OnMessage Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Class Members not getting set in OnMessage

    Hi,
    I was trying activeMQ with DMLC and got it to work for few topics. But I am facing with a strange scenario where in I have a class member which is a boolean flag and I am setting it after parsing the message that I receive in OnMessage(). But from what I have seen, even though the setting of the flag = true, it doesn't reflect to other members of the class. Only when I make the class members static then other members start seeing the change done. Can anybody explain me if I am doing any thing wrong ? Why are changes done in OnMessage bound only to the application conext and don't reflect globally?

    Thanks Shishir

  • #2
    So, you change instance field state at one of the class instances and wonder why don't you see the change at the other instances?

    Comment


    • #3
      Found the Solution

      Hi Denis,
      I think I found it, I was using the same class for publishing as well as receiving the message and hence had two beans. One as the startup beand other as messageListener bean. And since i made the flag variable static, both objects were able to see the flag. But I am having another curious thing happening. Once in a while i get the below error.

      "ERROR Service - Async error occurred: javax.jms.JMSExcept
      ion: Invalid acknowledgment: MessageAck"

      I haven't changed any DMLC settings but I get this error message and the listener doesn't receive the message but the ActiveMQ console shows as the message as consumed. Can you help me out on this one.

      Comment


      • #4
        Resolved but facing another problem

        Hi Dennis,
        Thanks for looking into the post but I was able to track and fix it. My mistake since I figured that I was instantiating the class twice, one as startup bean and second time as listener and hence the instance variables were local and when made static it worked. But after the fix(I instantiated DMLC programatically) I am having troubling in Listening to the message. I get the below error
        ERROR Service - Async error occurred: javax.jms.JMSExcept
        ion: Invalid acknowledgment: MessageAck
        Do you have any idea, if this occurs due to a particular reason. Any help will be greatly appreciated.

        Thanks
        Shishir

        P.S: I was not able to log into to forum from past one week. Looks like IE is not opening the site.

        Comment


        • #5
          Problem resolved

          Hi Dennis,
          This is my fourth or fifth attempt at trying to reply and every time the post gets filtered at moderation. Anyway I was able to figure out why the problem was occuring. It was due to the fact that I had same class as startup bean as well as topiclistener bean and hence two objects were getting instantiated and each having a local copy of the flag.
          But trying to figure our activeMQ and DMLC(instead of Jencks) I am facing some strange situation(ActiveMQ Web UI isnt helping either). I am instantiating the DMLC programatically by having a wrapper around it and if the destination is one the durable subscription gets registered and I can see it in activeMQ console. But if the list has 3-4 topics, even after starting the DMLC I don't see activeMQ showing it as registered.
          Here is my code sample
          Code:
          DefaultMessageListenerContainer dmlc = null;
          		String uniqueDurableSubscriptionName = null;
          		String uniqueClientId = null;
          		for(Destination destination:destinationList){
          			dmlc = new DefaultMessageListenerContainer();
          			dmlc.setConcurrentConsumers(Integer.valueOf(concurrentConsumers));
          			dmlc.setSessionAcknowledgeMode(Session.AUTO_ACKNOWLEDGE);
          			dmlc.setPubSubDomain(pubSubDomain);
          			dmlc.setSubscriptionDurable(subscriptionDurable);
          			dmlc.setSessionTransacted(sessionTransacted);
          
          			if(connectionFactory != null)
          				dmlc.setConnectionFactory(connectionFactory);
          			if(messageListener != null)
          				dmlc.setMessageListener(messageListener);
          			if(messageListener != null)
          				dmlc.setExceptionListener(exceptionListener);
          			if( !UfeedUtil.isAllBlanks(clientId)&& isSubscriptionDurable() && !UfeedUtil.isAllBlanks(durableSubscriptionName)){
          				++uniqueClientIdNumber;
          				uniqueDurableSubscriptionName = String.valueOf(uniqueClientIdNumber) + "-"+ durableSubscriptionName;
          				uniqueClientId = String.valueOf(uniqueClientIdNumber) + "-"+ clientId;
          				dmlc.setDurableSubscriptionName(uniqueDurableSubscriptionName);
          				dmlc.setClientId(String.valueOf(uniqueClientId));
          			}
          			try {
          				dmlc.setDestination(destination);
          				dmlc.afterPropertiesSet();
          				System.out.println("Started the " + ((Topic)destination).getTopicName()+ "subscriber");
          				if(!m_topicMesssageListenerContainerMap.containsKey(((Topic)destination).getTopicName()))
          					m_topicMesssageListenerContainerMap.put(((Topic)destination).getTopicName(), dmlc);
          			} catch (JMSException e) {
          				// TODO Auto-generated catch block
          				e.printStackTrace();
          			} catch (Exception e){
          				e.printStackTrace();
          			}
          
          		}
          any idea if I am missing any trick here?

          thanks
          shishir

          Comment


          • #6
            Problem resolved

            Hi Dennis,
            This is my fourth or fifth attempt at trying to reply and every time the post gets filtered at moderation. Anyway I was able to figure out why the problem was occuring. It was due to the fact that I had same class as startup bean as well as topiclistener bean and hence two objects were getting instantiated and each having a local copy of the flag.


            Thanks
            shishir

            P.S:One more attempt failed

            Comment

            Working...
            X