Universal Messaging Developer Guide : The Enterprise Client APIs : Overview of Enterprise Developer's Guide for Python : Enterprise Client Development : Universal Messaging Python : Subscribing to a Universal Messaging Channel/Topic or Queue
Universal Messaging Python : Subscribing to a Universal Messaging Channel/Topic or Queue
In the Universal MessagingPython API there is no object which represents a Universal Messaging Channel or Queue. In order to subcribe 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.

class Universal MessagingCallback(Universal MessagingPython.Universal MessagingCallback):
def onMessage(self,message):
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()
mySession.connect("nsp://localhost:9000")
chanName="demochannel"
mySession.subscribe(chanName,listener)
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".
Copyright © 2013-2014 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback