Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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