Receiving messages
Components inside Openvisulizer use messages to communicate with each other. There is a lot of messages. Subscribing to all of them will impact the latency of Openvisualizer and it's also likely that you are only interested in a subset of all messages.
You can use the control plane socket to set up which kind of messages you want to receive:
#!/usr/bin/env python import zmq context = zmq.Context() socket = context.socket(zmq.REQ) socket.connect ("tcp://localhost:50001") # To subscribe socket.send_json({"sub": ["bonjour"]}) # To unsubscribe # socket.send_json({"unsub": ["bonjour"]}) # you can even do both # socket.send_json({"sub": ["Hello"], "unsub": ["bonjour"]}) message = socket.recv() print(message) # You will get the subscriptions of the PUB socket {"subscriptions":["Hello"]}
Once this is set up, you can receive messages using a snippet of code similar to this :
#!/usr/bin/env python import zmq context = zmq.Context() subscriber = context.socket(zmq.SUB) subscriber.connect("tcp://localhost:50002") subscriber.setsockopt(zmq.SUBSCRIBE, "") while True: string = subscriber.recv_json() print(string)
Sending messages
There is a PULL socket waiting to receive message and inject them directly in the message bus. You can send message to the event bus by using a ZMQ PUSH socket like this:
#!/usr/bin/env python import zmq d = {'signal': 'my-signal', "sender": "external", "data": "Hello World!"} context = zmq.Context() publisher = context.socket(zmq.PUSH) publisher.connect("tcp://localhost:60000") publisher.send_json(d)