Examples¶
ZWG stands for ZeroMQ-Websocket-Gateway. It is a core component of the framework that allows communication between Producers and web clients.
ZWGP - Producers¶
Examples are provided in the lbto-dms package to demonstrate the ZeroMQ Websocket Gateway.
Open the webclient with your web browser: https://localhost/view-zwgd
Example producers can be started from a terminal.
Three flavors are provided in python:
cd /usr/share/lbto/dms/zwgp
sudo python demo-prod1
sudo python demo-prod2
sudo python demo-prod3
demo-prod1, follows a standard functional programming paradigm. It creates a Producer and implements its own loop.
demo-prod2, follows a callback paradigm. It creates a Producer, passes on a callback function and execute the producer’s mainloop.
demo-prod3, follows an object-oriented paradigm. It defines a new class derived from Producer that overloads callback method.
Another example program is provided in C++
cd /usr/share/lbto/dms/zwgp
make
sudo ./zwgp_demo
ZWGD - Daemon¶
zwgd is the daemon providing the communication between producers and web clients. It’s controlled and using the systemd facility.
# systemctl status dms_zwgd.service
● dms_zwgd.service - DMS zwg deamon
Loaded: loaded (/usr/lib/systemd/system/dms_zwgd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2021-05-15 18:35:43 MST; 2 days ago
Main PID: 808584 (zwgd)
Tasks: 3 (limit: 9499)
Memory: 28.5M
CPU: 6min 21.622s
CGroup: /system.slice/dms_zwgd.service
└─808584 /usr/bin/zwgd /etc/nginx/conf.d/zwgd.json
zwgd options are set using a JSON file, located in /etc/nginx/conf.d/zwgd.json
# cat /etc/nginx/conf.d/zwgd.json
{
"docroot": null
, "uri_pub": "ipc:///tmp/zwg_pubsub"
, "uri_pull": "ipc:///tmp/zwg_pushpull"
, "basic_auth": "/etc/nginx/conf.d/.htpasswd"
, "server_pem": "/etc/nginx/conf.d/server.pem"
, "m_polltimeout_ms": 50
, "ws_port": 8080
, "daemonize": false
, "log_level": 2
}
The options are described in the ZWGD section of this document.
For development purpose, you can increase for example the log level ("log_level": 3) and restart the daemon to take effect (systemctl restart dms_zwgd).
zwgd logs its output using systemd journal. You can inspect its activity using:
# journalctl -f -u dms_zwgd
ZWGC - Clients¶
Client examples are provided at the following url: https://localhost/view-zwgd
The CONNECT button establishes websocket connections to the underlying daemon.
The connection uses secured TLS/SSL wss:// and access is controlled by username and credentials.
To access the examples, use the username stream and password lbto.
Once a connection is established, the SUBSCRIBE, UNSUBSCRIBE, DISCONNECT control the subscription and connection for a particular example.
The web examples use a generic web-component configured for their specific use. It simply display the stream of messages coming from the producers.
Additional information about the webcomponent is provided in subsequent sections of this documents.