def setup(self, environ): # only post allowed by the JSON RPC handler api = Producer(self.cfg) handler = TaskQueueRpc(api) for consumer in api.consumers: rpc = consumer.rpc() if rpc: handler.putSubHandler(consumer.name, rpc) request = [Router('/', post=handler)] response = [GZipMiddleware(200)] return WsgiHandler(middleware=request, response_middleware=response)
def setup(self, environ): '''Called once only to setup the WSGI application handler. Check :ref:`lazy wsgi handler <wsgi-lazy-handler>` section for further information. ''' cfg = environ['pulsar.cfg'] loop = environ['pulsar.connection']._loop self.store = create_store(cfg.data_store, loop=loop) pubsub = self.store.pubsub(protocol=Protocol()) channel = '%s_webchat' % self.name ensure_future(pubsub.subscribe(channel), loop=loop) return WsgiHandler([Router('/', get=self.home_page), WebSocket('/message', Chat(pubsub, channel)), Router('/rpc', post=Rpc(pubsub, channel), response_content_types=JSON_CONTENT_TYPES)], [AsyncResponseMiddleware, GZipMiddleware(min_length=20)])
def gzip(self, request): response = self.info_data_response(request, gzipped=True) return GZipMiddleware(10)(request.environ, response)