Universal Messaging 9.8 | Universal Messaging 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 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):
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-2015 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.