4

We're using RabbitMQ + StompJS (w/ SockJS & Spring Websocket as middleware, FWIW) to facilitate broadcasting messages over websockets. Everything is working great, except no matter what we try StompJS creates the Queues as non-auto-delete, meaning we end up with TONS of queues.

We're working around it right now with a policy that cleans out inactive queues after several hours, but we'd rather just have auto-delete queues that terminate after all clients disconnect.

We've attempted setting headers auto_delete, auto-delete, autoDelete and every other possible incantation we can find.

If we stop an inspect the frames before they're transmitted (at the lowest possible level in the depths of StompJS's source) we can see those headers being present. However, they don't seem to be making it to RabbitMQ (or it just doesn't look at them on the "SUBSCRIPTION" command??) and creates them as non-auto-delete.

Interestingly, if we create the queue manually beforehand as auto-delete, the StompJS registration calls error out because the requested SUBSCRIBE expected non-auto-delete. This suggests that it's StompJS (or SockJS) that explicitly state non-auto-delete, but we've poured over the source and ruled that out.

So, the million dollar question: how can we have auto-delete queues with StompJS? Please, pretty please, and thanks in advance :)

Example registration

function reg(dest, callback, headers){
    stomp.subscribe(dest, callback, headers);
}

function cb(payload){
    console.log(JSON.parse(payload.body));
}

reg('/queue/foobar', cb, {});

Setup details RabbitMQ 3.5.2 and StompJS 2.3.3

** Note ** If I subscribe directly to the exchange (with destinations like /exchange/foo or /topic/foo) the exchange will be defined as auto-delete. It's only queues that aren't auto-delete.

David Welch
  • 1,941
  • 3
  • 26
  • 34

2 Answers2

0

I'm using StompJS/RabbitMQ in production and I'm not seeing this issue. I can't say for sure what your problem is, but I can detail my setup in the hope you might spot some differences that may help.

  • I'm running against Rabbit MQ 3.0.1.
  • I'm using SockJS 0.3.4, I seem to recall having some issues using a more recent release from GitHub, but unfortunately I didn't take notes so I'm not sure what the issue was.
  • I'm using StompJS 2.3.4

For reasons I won't go into here - I've disabled the WebSockets transport, by whitelisting all the other transports.

Here's some simplified code showing how I connect:

var socket = new SockJS(config.stompUrl, null, { protocols_whitelist: ['xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling'] });
var client = Stomp.over(socket);
client.debug = function () { };
client.heartbeat.outgoing = 0;
client.heartbeat.incoming = 0;

client.connect(config.rabbitUsername, config.rabbitPassword, function () {
   onConnected();
}, function () {
   reconnect(d);
}, '/');

And here's how I disconnect:

// close the socket first, otherwise STOMP throws an error on disconnect
socket.close();

client.disconnect(function () {
   isConnected = false;
});

And here's how I subscribe (this happens inside my onConnected function):

client.subscribe('/topic/{routing-key}', function (x) {
   var message = JSON.parse(x.body);

   // do stuff with message
});

My first recommendation would be to try the specific versions of the client libs I've listed. I had some issues getting these to play nicely - and these versions work for me.

Jim Liddell
  • 514
  • 3
  • 13
  • So your example works and would work well in most cases, but in my scenario I need the stomp client to bind directly to a queue (not a exchange). From what I can tell, if the destination is '/queue/foo' RabbitMQ will define the queue, but it's not auto_delete (and if it existed as auto-delete beforehand, an error is thrown) – David Welch Aug 04 '15 at 15:23
  • Ah - apologies, didn't appreciate that detail. Oh well. – Jim Liddell Aug 05 '15 at 08:24
0

It is possible with RabbitMQ 3.6.0+ by setting auto-delete in subscribe headers to true. Please see https://www.rabbitmq.com/stomp.html#queue-parameters for details.

Deepak Kumar
  • 944
  • 9
  • 12