123456789101112131415161718192021222324252627282930313233343536373839 |
- import uuid
- import library.paho.mqtt.client as mqtt
- import threading
- connect_count = 0
- lock = threading.Lock()
- def locust_on_connect(client, flags_dict, userdata, rc):
- global lock
- global connect_count
- print("client: {} connected, rc: {}".format(client, rc))
- lock.acquire()
- connect_count += 1
- print("connect_count: {}".format(connect_count))
- lock.release()
- def locust_on_subscribe(client, userdata, mid, granted_qos):
- print("client: {} subscribed, mid: {}".format(client, mid))
- def log(client, userdata, level, buf):
- print("[paho-log][client: {}] {}".format(client, buf))
- for x in range(0, 342):
- client = mqtt.Client(client_id = str(uuid.uuid1()))
- host = '127.0.0.1'
- port = 1883
- client.on_connect = locust_on_connect
- client.connect_async(host, port)
- client.loop_start()
- client.subscribe("/topic", 1)
- input("type enter to end")
|