Skip to content

Instantly share code, notes, and snippets.

@h3xagn
Created November 20, 2022 10:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save h3xagn/fbc9bd803b4f22f43adc9f7488b2df7c to your computer and use it in GitHub Desktop.
Streaming logs using RabbitMQ: https://h3xagn.com
// code from RabbitMQ
var wsbroker = "localhost";
var wsport = 15675;
var client = new Paho.MQTT.Client(
wsbroker,
wsport,
"/ws",
"myclientid_" + parseInt(Math.random() * 100, 10)
);
client.onConnectionLost = function (responseObject) {
console.log("CONNECTION LOST - " + responseObject.errorMessage);
};
client.onMessageArrived = function (message) {
var log = JSON.parse(message.payloadString);
var table = document.getElementById("log_table");
// removed some steps to add rows: see full code on GitHub
if (document.getElementById("check-auto-scroll").checked == true) {
cell.scrollIntoView();
};
};
var options = {
timeout: 3,
keepAliveInterval: 30,
onSuccess: function () {
console.log("CONNECTION SUCCESS");
client.subscribe("app1.ERROR", { qos: 1 });
client.subscribe("app2.ERROR", { qos: 1 });
client.subscribe("app3.DEBUG", { qos: 1 });
client.subscribe("app3.INFO", { qos: 1 });
client.subscribe("app3.WARNING", { qos: 1 });
client.subscribe("app3.ERROR", { qos: 1 });
},
onFailure: function (message) {
console.log("CONNECTION FAILURE - " + message.errorMessage);
},
};
if (location.protocol == "https:") {
options.us
eSSL = true;
}
console.log("CONNECT TO " + wsbroker + ":" + wsport);
client.connect(options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment