Subscribing to a Channel/Topic or Queue
In the Universal MessagingPython 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 Universal MessagingSession.subscribe method along with the Universal MessagingCallback object which will receive the asynchronous events.
Creating a Universal MessagingCallback Object
Asynchronously receiving events requires an object which implements the Universal MessagingPython.Universal MessagingCallback interface. The interface has one method, onMessage
which is passed a nConsumeEvent object (see Universal Messaging Events
class Universal MessagingCallback(Universal MessagingPython.Universal MessagingCallback):
print "received an event"
listener = Universal MessagingCallback()
Registering the Universal MessagingCallback Object to Receive Events
Once the Universal MessagingCallback 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 Universal MessagingSession (see Creating a Session
). Then you can call the Universal MessagingSession.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 = Universal MessagingSession()
Once the subscription has been registered, the onMessage method of the Universal MessagingCallback object will be invoked whenever a message is published onto the channel named "demochannel".