txredisapi:工厂立即停止

时间:2019-04-02 19:30:44

标签: python twisted

我正在使用扭曲服务器,其中服务器:websocket(高速公路)+ Flask服务器。

当我尝试实现this example以实现异步发布/订阅redis功能时,遇到了奇怪的工厂行为。

代码(在componentDidMount中):

then

日志(仅限redis工厂):

if __name__ == '__main__'

Redis协议:

log.startLogging(sys.stdout)
port = int(os.getenv('PORT', 5000))
ws_factory = Factory(u"ws://0.0.0.0:{}".format(port))
ws_factory.protocol = ClientProtocol
ws_factory.setProtocolOptions(autoPingInterval=2, autoPingTimeout=30)
ws_resource = WebSocketResource(ws_factory)
wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), app)

rootResource = WSGIRootResource(wsgi_resource,
                                {b'ws': ws_resource})

site = Site(rootResource)
reactor.listenTCP(port, site)
reactor.connectTCP("127.0.0.1", 6379, myFactory())
reactor.run()

如您所见,它没有连接(甚至没有达到web | 2019-04-02 19:15:05+0000 [-] Starting factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:05+0000 [Uninitialized] <twisted.internet.tcp.Connector object at 0x7f437c1b65c0> will retry in 2 seconds web | 2019-04-02 19:15:05+0000 [-] Stopping factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:08+0000 [-] Starting factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:08+0000 [Uninitialized] <twisted.internet.tcp.Connector object at 0x7f437c1b65c0> will retry in 8 seconds web | 2019-04-02 19:15:08+0000 [-] Stopping factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:16+0000 [-] Starting factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:16+0000 [Uninitialized] <twisted.internet.tcp.Connector object at 0x7f437c1b65c0> will retry in 21 seconds web | 2019-04-02 19:15:16+0000 [-] Stopping factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:38+0000 [-] Starting factory <__main__.myFactory object at 0x7f437c1b64a8> web | 2019-04-02 19:15:38+0000 [Uninitialized] <twisted.internet.tcp.Connector object at 0x7f437c1b65c0> will retry in 67 seconds web | 2019-04-02 19:15:38+0000 [-] Stopping factory <__main__.myFactory object at 0x7f437c1b64a8> 方法)。 Redis正在docker容器中的端口import txredisapi as redis5 class myProtocol(redis.SubscriberProtocol): def connectionMade(self): print("waiting for messages...") def messageReceived(self, pattern, channel, message): print("pattern=%s, channel=%s message=%s" % (pattern, channel, message)) def connectionLost(self, reason): print("lost connection:", reason) class myFactory(redis.SubscriberFactory): maxDelay = 120 continueTrying = True protocol = myProtocol 上运行,并确保已启动并准备连接。起初,我以为整个WSGI服务器都搞砸了,但是只使用了connectionMade 6379结果仍然相同。我尝试了其他几种方法来实现reactor.connectTCP("127.0.0.1", 6379, myFactory())

reactor.run()

txredisapi

这些都不起作用。

我想使用Redis发布/订阅功能来跟踪通过websocket发送的消息。

0 个答案:

没有答案