Following the RabbitMQ documentation I'm trying to subscribe and receive messages in the browser from the /topic/test
topic. Meanwhile to send them to RabbitMQ I'm using a program called mqtt-explorer.
In the console of the browser I'm able to see that the messages I'm sending actually arrive even though when I try to open RabbitMQ's managment portal I only see some queues automatically generated which always say that I have 0 messages on the queue.
This is what I'm sending with mqtt-explorer:
This is the browser when I'm connected as the same time as mqtt-explorer is sending:
If the browser is not connected in that moment the messages don't appear in the queue on RabbitMQ.
This is what I'm able to see when only mqtt-explorer is connected and is sending messages.
Below the code of the browser:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello MQTT</title>
</head>
<body>
<h1>Hello MQTT</h1>
<p>This is a basic HTML page with the title</p>
<!-- Source library -->
<script src="mqttws31.js" type="text/javascript"></script>
<script>
var wsbroker = "localhost"
var wsport = 15675; // port for above
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) {
console.log("RECEIVE ON " + message.destinationName + " PAYLOAD " + message.payloadString);
};
var options = {
timeout: 3,
keepAliveInterval: 30,
onSuccess: function () {
console.log("CONNECTION SUCCESS");
client.subscribe('/topic/test', {qos: 1});
},
onFailure: function (message) {
console.log("CONNECTION FAILURE - " + message.errorMessage);
}
};
console.log("CONNECT TO " + wsbroker + ":" + wsport);
client.connect(options);
</script>
</body>
</html>