嘗試在付費 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
但至少現在你看到你的代碼在某種程度上執行了。你只需要在進入循環之前以某種方式迴應一個可接受的返回代碼。不知道是否有可能在同一個請求上,你可能需要以不同的方式做。 –