Glossary:
Nirvana Python : Subscribing to a Nirvana Channel/Topic or Queue
In the NirvanaPython API there is no object which represents a Nirvana Channel or Queue. In order to subcribe 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.
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 Nirvana 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 Nirvana Channel or Queue that you wish to subscribe to and the second parameter is the Nirvana 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".
