Ejemplo n.º 1
0
 def pubsub(self, websocket):
     if not self._pubsub:
         # ``pulsar.cfg`` is injected by the pulsar server into
         # the wsgi environ. Here we pick up the name of the wsgi
         # application running the server. This is **only** needed by the
         # test suite which tests several servers/clients at once.
         name = websocket.handshake.environ['pulsar.cfg'].name
         self._pubsub = pubsub.PubSub(name=name)
         self._pubsub.subscribe('webchat')
     return self._pubsub
Ejemplo n.º 2
0
 def pubsub(self, websocket, room):
     if not room.slug in self._pubsub_cache.keys():
         # ``pulsar.cfg`` is injected by the pulsar server into
         # the wsgi environ. Here we pick up the name of the wsgi
         # application running the server. This is **only** needed by the
         # test suite which tests several servers/clients at once.
         name = websocket.handshake.environ['pulsar.cfg'].name
         self._pubsub_cache[room.slug] = pubsub.PubSub(name=name)
         self._pubsub_cache[room.slug].subscribe(room.slug)
     return self._pubsub_cache[room.slug]
Ejemplo n.º 3
0
    def setup(self):
        '''This method is called once only to setup the WSGI application
handler as described in :ref:`lazy wsgi handler <wsgi-lazy-handler>`
section. It creates a :ref:`publish/subscribe handler <apps-pubsub>`
and subscribe it to the ``webchat`` channel.'''
        backend = self.cfg.get('backend_server')
        self.pubsub = pubsub.PubSub(backend, encoder=self.encode_message)
        self.pubsub.subscribe('webchat')
        return wsgi.WsgiHandler([
            wsgi.Router('/', get=self.home_page),
            ws.WebSocket('/message', Chat(self.pubsub)),
            wsgi.Router('/rpc', post=Rpc(self.pubsub))
        ])
Ejemplo n.º 4
0
    def pubsub(self):
        '''A :class:`.PubSub` handler which notifies
and listen tasks execution status. There are three channels:

* ``<name>_task_created`` published when a new task is created.
* ``<name>_task_start`` published when the task queue starts executing a task.
* ``<name>_task_done`` published when a task is done.

All three messages are composed by the task id only. Here ``<name>`` is
replaced by the :attr:`.Backend.name` attribute of this task backend.

Check the :ref:`task broadcasting documentation <tasks-pubsub>` for more
information.
'''
        p = pubsub.PubSub(backend=self.connection_string, name=self.name)
        p.add_client(PubSubClient(self))
        c = self.channel
        p.subscribe(c('task_created'), c('task_start'), c('task_done'))
        return p
Ejemplo n.º 5
0
 def pubsub(self):
     p = pubsub.PubSub()
     p.subscribe('webchat')
     return p