autobahn を使用したパブリッシュ & サブスクライブ モデルでは、特定の のサブスクライバーの数を制限したいと考えてい@exportSub(...)
ます。チャンネル登録者数はどうやってわかりますか?
(例より)
class MyTopicService(object):
def __init__(self, allowedTopicIds):
self.allowedTopicIds = allowedTopicIds
@exportSub("", True)
def subscribe(self, topicUriPrefix, topicUriSuffix):
ret = False
print "client wants to subscribe to %s %s. Allowed topic ids:%s" % (topicUriPrefix, topicUriSuffix, self.allowedTopicIds)
try:
if topicUriSuffix in self.allowedTopicIds:
ret = True
print "Subscribing client to topic %s %s" % (topicUriPrefix, topicUriSuffix)
else:
print "Client not allowed to subscribe to topic %s %s" % (topicUriPrefix, topicUriSuffix)
except:
print "illegal topic - skipped subscription"
finally:
return ret
class MyServerProtocol(WampServerProtocol):
def onSessionOpen(self):
self.registerHandlerForPubSub(MyTopicService(my_keys_1), url_1_foo)
self.registerHandlerForPubSub(MyTopicService(my_keys_2), url_2_bar)
とメソッドをWampServerFactory
オーバーライドし、内部配列変数を使用して、おそらく独自の を使用してこれを行うことができます...しかし、よりクリーンな方法があるかどうか知りたいです...onClientSubscribed
onClientUnsubscribed
class MyFactory(WampServerFactory):
def onClientSubscribed(self, *a, **k):
WampServerFactory.onClientSubscribed(self, a, k)
print '=== client subscribed '
def onClientUnsubscribed(self, *a, **k):
WampServerFactory.onClientUnsubscribed(self, a, k)
print '=== client unsubscribed '
コードはここにあります。