forked from GlassyWing/stomp_ws_py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
32 lines (21 loc) · 744 Bytes
/
main.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
import json
import time
from stomp_ws.client import Client
import logging
def print_frame(frame):
print(json.loads(frame.body))
if __name__ == '__main__':
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
# open transport
client = Client("ws://127.0.0.1:8080/gs-guide-websocket")
# connect to the endpoint
client.connect(login="name",
passcode="45C82C421EBA87C8131E220F878E4145",
timeout=0)
# subscribe channel
client.subscribe("/topic/1", callback=print_frame)
# send msg to channel
client.send("/topic/1", body=json.dumps({'name': 'tom'}))
time.sleep(3)
client.disconnect()