Announcement Announcement Module
No announcement yet.
JMX Notification Listener Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMX Notification Listener

    I have a spring 2.5.6 application. The app uses HornetQ to send JMS messages to a topic consumer in a separate app. I have a timertask that periodically sends a "heartbeat" message on the JMS topic. In the same app, I also have a jmx managed bean and a jmx notification listener. My goal is to have the jmx notification listener send a message to the JMS topic whenever an attribute is changed.

    The issue is that the handleNotification() method of my jmx listener cannot seem to access the class which sends the jms message (called JmsTopicSender). If I try to call jmsTopicSender.sendMessage(userdataobj) using the property in the class, nothing happens. However, if I do:

    JmsTopicSender s = appContext.getBean("jmsTopicSender");

    the message is sent perfectly.

    I don't understand why the listener doesn't have access to attributes in the class. Can someone help explain??

    Here's the relevant part of my context file:
    <bean id="exporter"
        <property name="notificationListenerMappings">
            <entry key="*">
              <bean class=""/>
     <!-- Set up to use the default mbean server -->
        <bean  id="healthMonitor" class="">
            <property name="jmsTopicSender" ref="jmsTopicSender" />
        <!-- Create the topic for sending the heartbeat messages. -->
        <bean id="heartbeatTopic" class="org.hornetq.api.jms.HornetQJMSClient" factory-method="createTopic">
            <constructor-arg index="0" value="infrastructure.heartbeat"/>
        <!-- JMS Template -->
        <bean id="jmsTemplate"
         <property name="connectionFactory" ref="cachedConnectionFactory"></property>
        <!-- Bean to send JMS messages -->
        <bean id="jmsTopicSender" class="">
            <property name="jmsTemplate" ref="jmsTemplate" />
            <property name="destination" ref="heartbeatTopic"/>

    and the HealthMonitor code is:

    public class HealthMonitor implements NotificationListener, NotificationFilter {
        private static final long serialVersionUID = 1L;
        private static final Logger logger = LoggerFactory.getLogger( HealthMonitor.class );
        private DataFlowController dataFlowController;
        private JmsTopicSender jmsTopicSender;
        public void setDataFlowController(DataFlowController dataFlowController){
            this.dataFlowController = dataFlowController;
        public void setJmsTopicSender(JmsTopicSender jmsTopicSender) {
            this.jmsTopicSender = jmsTopicSender;
        //called by timertask
        public void checkHeartbeat() {
            logger.debug("checkHeartbeat... - Thread:  " + Thread.currentThread().getName());
            try {
                //this.jmsTopicSender.sendMessage("this is a string.");
            } catch (JMSException e) {
                // TODO Auto-generated catch block
      "coulndn't do send", e);
  "finished checkHeartbeat...");
        public void handleNotification(Notification notification, Object handback) {
  "Received notification from " + notification.getSource());
            try {
      "sending message with message = " + notification.getUserData());
            } catch (JMSException e) {
                // TODO Auto-generated catch block
      "coulndn't do send", e);
  "finished handleNotification()");
        public boolean isNotificationEnabled(Notification notification) {
            return AttributeChangeNotification.class.isAssignableFrom(notification.getClass());
    When an attribute is changed, the log file shows the message "sending message with message = ...", but nothing after it. The very first line in the jmsTopicSender.sendMessage() method is a log message and it is not getting recorded.

    2011-11-10 09:05:55,281 INFO  HealthMonitor - Received notification from spring:name=dataFlowController:  
    2011-11-10 09:05:55,281 INFO  HealthMonitor -  user data = an attribute has changed
    2011-11-10 09:05:55,281 INFO  HealthMonitor - sending message with message = an attribute has changed
    2011-11-10 09:06:39,911 DEBUG HealthMonitor - checkHeartbeat...
    2011-11-10 09:06:39,911 INFO  JmsTopicSender - heartbeat::: sending message to infrastructure.heartbeat
    2011-11-10 09:06:39,911 DEBUG JmsTemplate - Executing callback on JMS Session: Cached JMS Session: HornetQRASession->[email protected]
    2011-11-10 09:06:39,911 INFO  JmsTopicSender - Sending heartbeat ...
    2011-11-10 09:06:39,911 DEBUG JmsTemplate - Sending created message: HornetQMessage[null]:PERSISTENT
    2011-11-10 09:06:39,911 INFO  JmsTopicSender - heartbeat:::  done sending message to infrastructure.heartbeat
    2011-11-10 09:06:39,911 INFO  HealthMonitor - finished checkHeartbeat...