-
Notifications
You must be signed in to change notification settings - Fork 0
/
solace_client.py
36 lines (25 loc) · 1.01 KB
/
solace_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import paho.mqtt.client as mqtt
import ssl
def onConnect(client, userdata, flags, rc):
print('subscribing to topic: ')
client.subscribe("testing/client")
print('publishing...')
client.publish("testing/client", "test message")
def onDisconnect(client, userdata, rc):
print('disconnected!')
def onMessage(client, userdata, message):
print('got message: ' + str(message.payload))
connections='./solace.cloud'
connection_args = {}
with open(connections, "r") as f:
for line in f:
(key, val) = line.strip().split('=')
connection_args[key] = val
client = mqtt.Client(transport="websockets")
client.tls_set(ca_certs=None, certfile=None, keyfile=None, cert_reqs=ssl.CERT_REQUIRED, tls_version=ssl.PROTOCOL_TLS, ciphers=None)
client.on_connect = onConnect
client.on_disconnect = onDisconnect
client.on_message = onMessage
client.username_pw_set(connection_args['username'], password=connection_args['password'])
client.connect(connection_args['url'], int(connection_args['port']), 20)
client.loop_forever()