Web-Stomp Web browser communication

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 publishto 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 ws = new SockJS("https://blue-horse.rmq.cloudamqp.com/stomp");
var client = Stomp.over(ws);

// 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

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