Web-Stomp Web browser communication

RabbitMQ is a message broker that allows clients to connect over a range of different open and standardized protocols such as AMQP, HTTP, STOMP, MQTT, MQTT over websockets and WebSockets/Web-Stomp.

Web-Stomp is a plugin to RabbitMQ which exposes a WebSockets server (with fallback) so that web browsers can communicate with your RabbitMQ server/cluster directly.

The Web-Stomp plugin is only enabled on dedicated plans.

To use Web-Stomp you first need to create at least one user, with limited permissions, or a new vhost which you can expose publicly, because the username/password must be included in your javascript, and non limited user can subscribe and publish to any queue or exchange.

Next include socks.min.js and stomp.min.js in your HTML from for example CDNJS:

<script src="//cdnjs.cloudflare.com/ajax/libs/sockjs-client/0.3.4/sockjs.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.min.js"></script>

To connect:

// Replace with your hostname
var wss = new SockJS("wss://blue-horse.rmq.cloudamqp.com/ws/stomp");
var client = Stomp.over(wss);

// RabbitMQ SockJS does not support heartbeats so disable them
client.heartbeat.outgoing = 0;
client.heartbeat.incoming = 0;

client.debug = onDebug;

// Make sure the user has limited access rights
client.connect("webstomp-user", "webstomp-password", onConnect, onError, "vhost");

function onConnect() {
  var id = client.subscribe("/exchange/web/chat", function(d) {
    var node = document.createTextNode(d.body + '\n');
    document.getElementById('chat').appendChild(node);
  });
}

function sendMsg() {
  var msg = document.getElementById('msg').value;
  client.send('/exchange/web/chat', { "content-type": "text/plain" }, msg);
}

function onError(e) {
  console.log("STOMP ERROR", e);
}

function onDebug(m) {
  console.log("STOMP DEBUG", m);
}

A full example can be found here: github.com/cloudamqp/web-stomp-example

You can also use the WebSocket API directly: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

Note that our servers have nginx infront of them that will perform TLS/SSL-termination. You can only connect over HTTPS; HTTP is not allowed.

If you have any questions, please feel free to contact support@cloudamqp.com for further assistance.