尝试在付费 GAE应用程序上运行简单的MQTT客户端(不是代理)。然而一个on_connect
回调从来没有发生在以下:如何让MQTT客户端在Appengine上运行(python)
worker.py
import webapp2
import paho.mqtt.client as paho
class WorkerHandler(webapp2.RequestHandler):
def on_subscribe(client, userdata, mid, granted_qos):
print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
def on_connect(client, userdata, flags, rc):
client.subscribe("$SYS/#")
print "Subscribed to wildcard"
def get(self):
client = paho.Client()
client.on_connect = self.on_connect
client.on_subscribe = self.on_subscribe
client.on_message = self.on_message
client.connect("iot.eclipse.org")
print "connected to broker"
client.loop_forever()
app = webapp2.WSGIApplication([
(r'/_ah/start', WorkerHandler),
])
在开发环境它只是一个消息,一分钟后,静静地失败或使
INFO 2017-04-04 01:51:40,958 module.py:813] worker: "GET /_ah/start HTTP/1.1" 500 220
INFO 2017-04-04 01:51:41,869 module.py:1759] New instance for module "worker" serving on: http://localhost:8080
connected to broker
WARNING 2017-04-04 01:52:10,860 module.py:1927] All instances may not have restarted
此配置作为“后端”/服务和yaml看起来像这样:
worker.yaml
注意:在开发环境,socket.py是直接从蟒蛇进口安装.../2.7/lib中/ python2.7/socket.py
是的,它最初是作为一个应用程序运行。该脚本仍然运行,因为它不需要任何http处理程序。我已经将它改回到结果没有改变的情况。 – Fakeer
但至少现在你看到你的代码在某种程度上执行了。你只需要在进入循环之前以某种方式回应一个可接受的返回代码。不知道是否有可能在同一个请求上,你可能需要以不同的方式做。 –