2023-01-14 12:40:08 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
import os
|
|
|
|
|
from taosws import Consumer
|
|
|
|
|
|
|
|
|
|
endpoint = os.environ["TDENGINE_CLOUD_ENDPOINT"]
|
|
|
|
|
token = os.environ["TDENGINE_CLOUD_TOKEN"]
|
|
|
|
|
|
|
|
|
|
conf = {
|
|
|
|
|
# auth options
|
2023-01-18 07:16:55 +00:00
|
|
|
"td.connect.websocket.scheme": "wss",
|
|
|
|
|
"td.connect.ip": endpoint,
|
2023-01-14 12:40:08 +00:00
|
|
|
"td.connect.token": token,
|
|
|
|
|
# consume options
|
|
|
|
|
"group.id": "test_group_py",
|
|
|
|
|
"client.id": "test_consumer_ws_py",
|
|
|
|
|
}
|
|
|
|
|
consumer = Consumer(conf)
|
|
|
|
|
|
|
|
|
|
consumer.subscribe(["test"])
|
|
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
|
message = consumer.poll(timeout=1.0)
|
|
|
|
|
if message:
|
|
|
|
|
id = message.vgroup()
|
|
|
|
|
topic = message.topic()
|
|
|
|
|
database = message.database()
|
|
|
|
|
|
|
|
|
|
for block in message:
|
|
|
|
|
nrows = block.nrows()
|
|
|
|
|
ncols = block.ncols()
|
|
|
|
|
for row in block:
|
|
|
|
|
print(row)
|
|
|
|
|
values = block.fetchall()
|
|
|
|
|
print(nrows, ncols)
|
|
|
|
|
else:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
consumer.close()
|