Hi, I am trying to create a listener inside the NOX script to listen to changes in a variable done externally. The script listener.py attached with this email runs fine by itself. I'm not sure where to add it in the NOX script because the script listener.py also needs a time.sleep() for it to listen indefinitely. I'd be highly obliged if you could guide me where to add the listener part in the NOX script. I tried to add the listener part to my NOX script as follows; but it didn't work. STOMP connect was setup in the beginning but was lost soon.
# listener code starts ===================================
import time
import sys
import os
import stomp
import Globals
user = os.getenv("STOMP_USER") or "admin"
password = os.getenv("STOMP_PASSWORD") or "password"
host = os.getenv("STOMP_HOST") or "localhost"
port = os.getenv("STOMP_PORT") or 61613
destination = sys.argv[1:2] or ["/topic/event"]
destination = destination[0]
# listener code ends ===================================
class lbtest(Component):
def install(self):
self.register_for_packet_in(self.packet_in_callback)
.......other callback functions...............
def getInterface(self):
return str(lbtest)
def __init__(self, ctxt):
Component.__init__(self, ctxt)
Globals.COMPONENT = self
# listener code starts ===================================
conn = stomp.Connection(host_and_ports = [(host, port)])
conn.set_listener('', MyListener(conn))
conn.start()
conn.connect(login=user,passcode=password)
conn.subscribe(destination=destination, ack='auto')
Globals.log.info("Waiting for messages...")
# listener code ends ===================================
......some definitions...
# ===================================
# Factory
# ===================================
def getFactory():
class Factory:
def instance(self, ctxt):
return lbtest(ctxt)
return Factory()
# listener code starts ===================================
# ===================================
# Stomp listener for VIP change
# ===================================
class MyListener(object):
def __init__(self, conn):
self.conn = conn
def on_error(self, headers, message):
Globals.log.info('received an error ' + message)
def on_message(self, headers, message):
Globals.VIP=message
Globals.log.info('New VIP: '+Globals.VIP)
# listener code ends ===================================
Regards,
Neha
listener.py
Description: Binary data
