stompjs + rabbitmq - create Auto-Delete queues

时间:2015-07-31 20:53:51

标签: websocket rabbitmq stomp stompjs

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.

2 个答案:

答案 0 :(得分:0)

RabbitMQ 3.6.0+可以通过将订阅标头中的class="row设置为auto-delete来实现。有关详细信息,请参见https://www.rabbitmq.com/stomp.html#queue-parameters

答案 1 :(得分:-1)

我在制作中使用StompJS / RabbitMQ,但我没有看到这个问题。我无法确定您的问题是什么,但我可以详细说明我的设置,希望您可以发现一些可能有帮助的差异。

  • 我正在对抗Rabbit MQ 3.0.1。
  • 我正在使用SockJS 0.3.4,我似乎记得使用GitHub的最新版本时遇到了一些问题,但不幸的是我没有记笔记,所以我不确定是什么问题是。
  • 我正在使用StompJS 2.3.4

由于我不会进入这里的原因 - 我通过将所有其他传输列入白名单来禁用WebSockets传输。

这里有一些显示我如何连接的简化代码:

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);
}, '/');

以下是我如何断开连接:

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

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

以下是我订阅的方式(这发生在我的onConnected函数中):

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

   // do stuff with message
});

我的第一个建议是尝试我列出的客户端库的特定版本。我有一些问题让这些版本很好玩 - 这些版本对我有用。