3
:copyright: Copyright 2006-2009 by Oliver Schoenborn, all rights reserved.
4
:license: BSD, see LICENSE.txt for details.
9
# ------------ create some listeners --------------
12
def onTopic11(self, msg, msg2, extra=None):
13
print 'Method Listener.onTopic11 received: ', `msg`, `msg2`, `extra`
15
def onTopic1(self, msg, topic=pub.AUTO_TOPIC):
16
info = 'Method Listener.onTopic1 received "%s" message: %s'
17
print info % (topic.getName(), `msg`)
19
def __call__(self, **kwargs):
20
print 'Listener instance received: ', kwargs
22
listenerObj = Listener()
25
def listenerFn(msg, msg2, extra=None):
26
print 'Function listenerFn received: ', `msg`, `msg2`, `extra`
28
# ------------ subscribe listeners ------------------
30
pub.subscribe(listenerObj, pub.ALL_TOPICS) # via its __call__
32
pub.subscribe(listenerFn, 'topic_1.subtopic_11')
33
pub.subscribe(listenerObj.onTopic11, 'topic_1.subtopic_11')
35
pub.subscribe(listenerObj.onTopic1, 'topic_1')