Universal Messaging 10.7 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for Python | Enterprise Client Development | Subscribing to a Channel/Topic or Queue
 
Subscribing to a Channel/Topic or Queue
In the NirvanaPython API there is no object which represents a Universal Messaging Channel or Queue. In order to subscribe you simply pass the name of the destination to the NirvanaSession.subscribe method along with the NirvanaCallback object which will receive the asynchronous events.
Creating a NirvanaCallback Object
Asynchronously receiving events requires an object which implements the NirvanaPython.NirvanaCallback interface. The interface has one method, onMessage which is passed a nConsumeEvent object (see Universal Messaging Events).

class NirvanaCallback(NirvanaPython.NirvanaCallback):
def onMessage(self,message):
print "received an event"

listener = NirvanaCallback()
Registering the NirvanaCallback Object to Receive Events
Once the NirvanaCallback object is created you need to register that object as a listener on the Universal Messaging Channel or Queue. First of all you need to construct a NirvanaSession (see Creating a Session). Then you can call the NirvanaSession.subscribe method where the first parameter is the name of the Universal Messaging Channel or Queue that you wish to subscribe to and the second parameter is the Universal Messaging Callback object.

mySession = NirvanaSession()
mySession.connect("nsp://localhost:9000")
chanName="demochannel"
mySession.subscribe(chanName,listener)
Once the subscription has been registered, the onMessage method of the NirvanaCallback object will be invoked whenever a message is published onto the channel named "demochannel".